数据库只查找值不能为NULL的列名
注意:我只要显示出必需填值域的列名,多余的可为NULL的列名不要显示出来。由于列比较多,必填的也很多,而且列名又长又难记,我不可能一个一个的selectt.a,t.b,t...
注意:我只要显示出必需填值域的列名,多余的可为NULL的列名不要显示出来。由于列比较多,必填的也很多,而且列名又长又难记,我不可能一个一个的 select t.a , t.b , t.c...... from t 希望指点一下,SQL和oracle 如果语句有不一样,两个都要给出。。
展开
2个回答
展开全部
sqlserver:
create procedure QueTable(@TabName varchar(50)) as
begin
declare
@sql nvarchar(4000),
@col nvarchar(4000),
@na nvarchar(255)
set @sql='select '
declare curtab cursor for
select a.name From syscolumns a, sysobjects b
where a.id = b.id
and b.name = @tabname
and a.isnullable = 0
set @col=''
open curtab
fetch next from curtab into @na
while @@fetch_status = 0
begin
set @col = @col + @na + ','
fetch next from curtab into @na
end
close curtab
DEALLOCATE curtab
set @col = substring(@col, 1, len(@col) -1)
if @col = ''
begin
print @tabname + '表中无非空列'
return
end
set @sql = @sql + @col + ' from ' + @TabName
execute sp_executesql @sql
end
go
exec quetable 'sysobjects'
create procedure QueTable(@TabName varchar(50)) as
begin
declare
@sql nvarchar(4000),
@col nvarchar(4000),
@na nvarchar(255)
set @sql='select '
declare curtab cursor for
select a.name From syscolumns a, sysobjects b
where a.id = b.id
and b.name = @tabname
and a.isnullable = 0
set @col=''
open curtab
fetch next from curtab into @na
while @@fetch_status = 0
begin
set @col = @col + @na + ','
fetch next from curtab into @na
end
close curtab
DEALLOCATE curtab
set @col = substring(@col, 1, len(@col) -1)
if @col = ''
begin
print @tabname + '表中无非空列'
return
end
set @sql = @sql + @col + ' from ' + @TabName
execute sp_executesql @sql
end
go
exec quetable 'sysobjects'
展开全部
select * from where column is not null
更多追问追答
追问
不行,会提示无效字符,在 column 这边
追答
column是你的哪一列,你得自己写列名,如果是多个列的话,你可以用and关系运算符,如select * from tablename where column1is not null and column2 is not null
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询