首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求解。解决方法

2012-11-22 
求解。。。。SQL codedeclare @where nvarchar(100)declare @NotGDChnCount intdeclare @sql nvarchar(1000)se

求解。。。。

SQL code
    declare @where nvarchar(100)    declare @NotGDChnCount int    declare @sql nvarchar(1000)    set @sql=N'select @Count=COUNT(distinct id) from GoldCardReplacementData    where DataType=1 '    EXEC sp_executesql @sql,N'@Count int output',@NotGDChnCount output    select @NotGDChnCount    print @sql

以上为我的代码,在@sql中要是不加上@where变量,语句能正常执行,如果加了@where,就查不出任何东西,请问各位,这是为什么呢?

[解决办法]
加了以后的语句贴出来看看
[解决办法]
探讨
解决了,@where变量初始化下就能用了。。。

[解决办法]
try
SQL code
    declare @where nvarchar(100)    declare @NotGDChnCount int    declare @sql nvarchar(1000)    SET @where=' where DataType=1 '    set @sql=N'select @Count=COUNT(distinct id) from GoldCardReplacementData'+@where    EXEC sp_executesql @sql,N'@Count int output',@NotGDChnCount output    select @NotGDChnCount    print @sql
[解决办法]
我就说你都只有定义没有使用....
[解决办法]
恭喜楼主自立更生
[解决办法]
where 里面给成1=1 先给个 让where恒成立
[解决办法]
探讨

我就说你都只有定义没有使用....

[解决办法]
探讨

解决了,@where变量初始化下就能用了。。。

热点排行