如何在表中选择仅包含所有行的特定值的列?我正在尝试查找这些列,以便对NULL
值的值进行更新。在我的专栏中,我有各种各样的值,包括NA
我正在使用SQL Server 2012
。
我尝试过:thsi只给我列名。我是否可以为值为' NA'?
的列添加此条件SELECT COLUMN_NAME AS NAMES,COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'ABC'
我是SQL
的初学者。试图找出如何做到这一点。
答案 0 :(得分:1)
如果列的min等于max,则该列包含相同的值:
foo = {1:0.001,2:2.097,3:1.093,4:5.246}
foo.pop(2)
new_foo = {i: value for i, (_, value) in enumerate(sorted(foo.items()), start=1)}
print new_foo
使用动态查询:
foo = [0.001, 2.097, 1.093, 5.245]
foo.pop(1) # list indices start at 0
print foo
答案 1 :(得分:0)
尝试这个查询
DECLARE @SQLQUERY NVARCHAR(MAX)
declare @tableName varchar(50)
DECLARE @NAME VARCHAR(50)
Declare @ParamDefinition AS NVarchar(2000)
Set @ParamDefinition = '@OIM VARCHAR(20)'
SELECT NAME
FROM sys.objects
WHERE [object_id]=@OIM
set @tableName= (SELECT NAME
FROM sys.objects
WHERE [object_id]=@OIM)
SET @NAME=(SELECT C.NAME
FROM sys.columns c
JOIN
sys.tables t ON c.object_id = t.object_id
WHERE c.name in (select distinct name
from sys.columns
where object_id=@OIM))
SET @SQLQUERY = ''
SELECT @SQLQUERY = @SQLQUERY + 'UPDATE ' + @tableName + ' SET ' + @NAME + ' = NULL WHERE ' + @NAME + ' = NA ; '
PRINT @SQLQUERY
Execute sp_Executesql @SQLQUERY , @ParamDefinition, @OIM
end