检查SQL Server表中的重复名称 [英] Check duplicate names in SQL server table
本文介绍了检查SQL Server表中的重复名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i有这样的表格。
id name class
1 A null
2 B null
3 c null
4 d null
1 A 9
3 c 9 >
如何检查具有位值的数据是否存在。我需要以下输出。
id名称类存在
1 A null 0
2 B null 0
3 c null 0
4 d null 0
1 A 9 1
3 c 9 1 >
问候
Kishore
我尝试过:
SELECT Id,name,class
(isnull(class,123)= 123然后0 else 1 end)存在
FROM test_Table
解决方案
添加逗号...
SELECT Id,name,class
( case 当 isnull(class, 123 )= 123 然后 0 else 1 结束) as 存在
FROM test_Table成为:
SELECT ID,name,class,
( case 当 isnull(class, 123 )= 123 然后 0 else 1 end ) as 存在
FROM test_Table
但我可能会采用更安全的方式:
SELECT Id,Name ,Class, CASE WHEN 类 IS < span class =code-keyword> NULL 那么 0 ELSE 1 结束 AS 存在
FROM test_Table
Hi all,
i have below table like this.
id name class
1 A null
2 B null
3 c null
4 d null
1 A 9
3 c 9
how to check data with bit value is exist or not. i need below output.
id name class exist
1 A null 0
2 B null 0
3 c null 0
4 d null 0
1 A 9 1
3 c 9 1
regards
Kishore
What I have tried:
SELECT Id,name,class (case when isnull(class,123)=123 then 0 else 1 end) as exist FROM test_Table
解决方案
Add a comma...
SELECT Id,name,class (case when isnull(class,123)=123 then 0 else 1 end) as exist FROM test_TableBecomes:
SELECT Id,name,class, (case when isnull(class,123)=123 then 0 else 1 end) as exist FROM test_Table
But I'd probably do it a safer way:
SELECT Id, Name, Class, CASE WHEN Class IS NULL THEN 0 ELSE 1 END AS Exist FROM test_Table
这篇关于检查SQL Server表中的重复名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文