如何根据Charecter长度比较表行中的三列...还需要使用Null值更新最高列 [英] How to compare three columns in a table row based on its Charecter length...also need to update the highest column with Null value

查看:53
本文介绍了如何根据Charecter长度比较表行中的三列...还需要使用Null值更新最高列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据Charecter长度比较表格行中的三列...还需要用Null值更新最高列



如果有三列列数值

一个,

两个

三个



我想要比较这三个coulmn,并找到最大的列与许多字符

在上面的输入三是最大的列。所以需要用null值更新该列或第一个字符即'T'



任何建议请

How to compare three columns in a table row based on its Charecter length...also need to update the highest column with Null value

If there is three column with values
one,
Two
Three

I want to compare this threee coulmn and find the biggest column with many charecters
In the above input "Three" is the biggest column.So need to update that column with "null" value or First charecter i.e 'T'

Any suggestions please

推荐答案

首先:这听起来像数据应该在行中而不是单行上的列...



但是,一种方法是简单地比较值长度,如果最长则返回更新语句,返回null,如果不是则返回原始值。



换句话说,就像

First of all: This sounds like the data should be in rows instead of columns on a single row...

However, one way is to simply compare the value lengths and in the update statement if longest, return null and if not then return the original value.

In other words, something like
UPDATE MyTable
SET mycolumn1 = CASE 
                   WHEN LEN(mycolumn1) > LEN(mycolumn2) AND LEN(mycolumn1) > LEN(mycolumn3) THEN NULL 
				   ELSE mycolumn1
			    END,
	mycolumn2 = CASE 
                   WHEN LEN(mycolumn2) > LEN(mycolumn1) AND LEN(mycolumn2) > LEN(mycolumn3) THEN NULL 
				   ELSE mycolumn2
			    END,
	mycolumn3 = CASE 
                   WHEN LEN(mycolumn3) > LEN(mycolumn1) AND LEN(mycolumn3) > LEN(mycolumn2) THEN NULL 
				   ELSE mycolumn3
			    END



但是如上所述,我感觉存储数据因为行是可行的解决方案......


But as said, I have a feeling that storing the data as rows would be the feasible solution...


这篇关于如何根据Charecter长度比较表行中的三列...还需要使用Null值更新最高列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆