夜深人静,可以产生冥想,可还有一个语句想不出来!能否帮帮我!
DECLARE @state int,@pname char(5)
DECLARE @tj1 char(200)
SET @state =23
set @tj1='CASE WHEN @state > 0 then ProductID else 0 end=CASE WHEN @state > 0 then @state else 0 end'
select ProductID,ProductName from Products where @tj1
我想直接取出@tj1 的值放在where 语句里面,怎么报错呢? 应该怎么做呢?谢谢大家了!辛苦您了!
Server: Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near '0'.
Server: Msg 170, Level 15, State 1, Line 9
Line 9: Incorrect syntax near '@tj1'.
如果我直接放'CASE WHEN @state > 0 then ProductID else 0 end=CASE WHEN @state > 0 then @state else 0 end 在where 后面是可以运行的!
问题点数:20、回复次数:3Top
1 楼internetcsdn(2003-8-7 9:20:26)回复于 2004-05-02 23:52:06 得分 20
DECLARE @state int,@pname char(5)
DECLARE @tj1 char(200)
SET @state =23
set @tj1='CASE WHEN @state > 0 then ProductID else 0 end=CASE WHEN @state > 0 then @state else 0 end'
exec('select ProductID,ProductName from Products where'+@tj1)Top
2 楼honey888(踏实做人)回复于 2004-05-02 23:59:27 得分 0
谢谢楼上兄弟!Top
3 楼internetcsdn(2003-8-7 9:20:26)回复于 2004-05-03 00:00:10 得分 0
客气客气Top




