如何查询出col4列的布尔表达式结果为true的记录 最好一条SQL语句

2020-06-19 文化 117阅读
这个貌似只能用循环加动态sql去解决,一条语句实在想不出来
IF object_id('tempdb.dbo.#t') is not null
drop table #t
declare @col1 varchar(1),@col2 varchar(2),@col3 varchar(2),@col4 varchar(800),@sql nvarchar(2000)
create table #t
(
[col1] varchar(1),
[col2] varchar(2),
[col3] varchar(2),
[col4] varchar(800))
declare c1 cursor for
select * from tb
open c1
fetch next from c1 into @col1,@col2,@col3,@col4
WHILE @@FETCH_STATUS = 0
begin
print @col1
set @sql='insert into #t select '+''''+@col1+''''+','+''''+@col2+''''+','+''''+@col3+''''+','+''''+@col4+''''+' where '+@col4
print @sql
exec(@sql)
fetch next from c1 into @col1,@col2,@col3,@col4
end
CLOSE c1
DEALLOCATE c1
select * from #t
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com