社区
MS-SQL Server
帖子详情
这段简单的动态创建的查询代码有什么问题??
dxhh99
2005-04-12 11:35:06
declare @f1 decimal(6,2)
select @f1=合计费用 from 一月份 where 电话号码=5951355
select @f1
成功运行
declare @f1 decimal(6,2)
declare @s varchar(100)
set @s='select @f1=合计费用 from 一月份 where 电话号码=5951355'
exec(@s)
select @f1
运行是提示变量f1没有定义。
...全文
70
6
打赏
收藏
微信扫一扫
点击复制链接
分享
下载分享明细
分享
举报
写回复
6 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Well
2005-04-14
declare @s varchar(100)
Set @s=N'declare @f1 decimal(6,2)'
Set @s=@s+N'select @f1=合计费用 from 一月份 where 电话号码=5951355'
Set @s=@s+N'select @f1'
exec(@s)
打赏
举报
回复
赞
mouseanAnya
2005-04-12
啊,已经有回复了,当我没来过
打赏
举报
回复
赞
talantlee
2005-04-12
declare @s varchar(100)
set @s=N' declare @f1 decimal(6,2)
select @f1=合计费用 from 一月份 where 电话号码=5951355'
print @f1'
exec(@s)
打赏
举报
回复
赞
mouseanAnya
2005-04-12
declare @s varchar(100)
set @s='declare @f1 decimal(6,2);select @f1=合计费用 from 一月份 where 电话号码=5951355;select @f1'
exec(@s)
打赏
举报
回复
赞
paoluo
2005-04-12
你可以这样。
第二段代码改为
declare @s varchar(100)
Set @s=N'declare @f1 decimal(6,2)'
Set @s=@s+N'select @f1=合计费用 from 一月份 where 电话号码=5951355'
Set @s=@s+N'select @f1'
exec(@s)
打赏
举报
回复
赞
paoluo
2005-04-12
因为你的declare @f1 decimal(6,2),在@s这段语句之外,所以会提示变量未定义。
打赏
举报
回复
赞
相关推荐
SqlServer动态in
declare @s varchar(500)set @s='13030,12581'exec('select * from novel where novelid in ('+@s+')') C#中SqlCommand cmd=con.CreateCommand();cmd.CommandText="exec('select * from novel where novelid in...
SQL SERVER 动态
查询
DECLARE @id INT,@sql VARCHAR(3333);--声明两个变量; SELECT @id=3; --给变量@id赋值; SELECT @sql='SELECT f_id,f_name FROM fruits WHERE f_id= ' EXEC(@sql + @id);---等同于“SELECT f_id,f_name FROM fru
MySQL
查询
多张表中类型相同字
段
的最大值
表结构 实现一:利用MySQL函数:GREATEST(value1,value2,...) SELECT GREATEST( (SELECT max(price) from tb_goods), (SELECT max(price) from tb_goods2) ) 实现二:利用存储过程 -- 使用存储过程 delimiter @@ create PROCEDURE fun (OUT res VARCHAR(10)) BEGIN DECLARE m1 DECIMAL(6,2); DECLARE
拼接存储过程 数据保留2位小数
alter proc stu @where varchar(100) as declare @sql nvarchar(200) set @sql='select sname,birth,CAST(score AS DECIMAL(18,2)) AS score from student' set @sql=@sql+' '+@where exec(@sql) go exec st
sql
查询
动态表名的记录
declare @table varchar(100) select @table=sParamterValue from table where id='sParamentCode' exec('select * from '+@table+'..DataBaseName')
发帖
MS-SQL Server
微信扫一扫
点击复制链接
分享社区
下载分享明细
3.3w+
社区成员
25.4w+
社区内容
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
帖子事件
创建了帖子
2005-04-12 11:35
社区公告
暂无公告