读书人

sql server 一点小疑点

发布时间: 2012-02-11 09:51:34 作者: rapoo

sql server 一点小问题 在线等
select cValue from dbo.AccInformation where cname like 'iLastPeriod'

select cpdcode,iperiodindex,dbegindate,denddate
from Period 这是两张表
当查询这张表的时候 判断 iperiodindex 和 select cValue from dbo.AccInformation where cname like 'iLastPeriod'
这张表的值是否相同 自动添加一列来做标记

[解决办法]

SQL code
select cpdcode,iperiodindex,dbegindate,denddate  ,case when iperiodindex = (select top 1 cValue from dbo.AccInformation where cname like 'iLastPeriod') then 1 else 0 end as 标记from Period
[解决办法]
上面效率太差

SQL code
declare @cValue  varchar(100)  --根据实际修改类型select top 1 @cValue = cValue from dbo.AccInformation where cname like 'iLastPeriod'select cpdcode,iperiodindex,dbegindate,denddate  ,case when iperiodindex = @cValue then 1 else 0 end as 标记from Period 

读书人网 >SQL Server

热点推荐