create procedure Upro
@tbname nvarchar(50)
,@YIDValue nvarchar(50)
asexec ('select max(XID) from ' + @tbname + ' where YID=''' +@YIDValue + '''')
@tbname nvarchar(50)
,@YIDValue nvarchar(50)
asexec ('select max(XID) from ' + @tbname + ' where YID=''' +@YIDValue + '''')
解决方案 »
- 怎么写一个sql语句,可以检查一个字段的值,如果是true返回1,是false返回0?多谢!
- 网站中sql server 2000 的一个字段等于另外一个字段+100的问题
- 有关触发器的!~~~
- 请问:如何用sql语句来实现adoquery.recno的功能
- sql循环查询
- 怎样消除Sql server 2008 R2中sql文件中的红色波浪线
- 求一SQL语句(可能比较复杂,在线...)
- 令人困惑的select语句
- 如何快速学会SQL SERVER2000,没有SQL SERVER基础,但是有一些数据库基础(如ACCESS,FOXPRO),一定给分,我的问题没有不给分的!
- 数据分区后移动旧数据至其它表中,报这个错误,到底什么原因,怎么解决
- 为什么全文索引不能查中文?
- 请问:怎么实现,数据库中所有用户类型的数据表一次性清空?
as
begin
declare @str nvarchar(1000)
select @str = 'SELECT @out =MAX('+@xid+' from '+@tablename +
'where '+@yid + '=' +@where
exec sp_executesql @str, '@out int output',@out output
end
go
create proc up_test (@tablename varchar(256),@xid varchar(256),@yid varchar(256), @where varchar(800),@out int output)
as
begin
declare @str nvarchar(1000)
select @str = 'SELECT @out =MAX('+@xid+') from '+@tablename +
' where '+@yid + '=' +@where
print @str
exec sp_executesql @str, N'@out int output',@out output
end
go
go
create proc up_test (@tablename varchar(256),@xid varchar(256),@yid varchar(256), @where varchar(800),@out int output)
as
begin
declare @str nvarchar(1000)
select @str = 'SELECT @out =MAX('+@xid+') from '+@tablename +
' where '+@yid + '=' +@where
exec sp_executesql @str, N'@out int output',@out output
end
go
exec up_test 't_inlist','f_inid','f_drugid','000000'
create proc up_test (@tablename varchar(256),@xid varchar(256),@yid varchar(256), @where varchar(800),@out int output)
as
begin
declare @str nvarchar(1000)
select @str = 'SELECT @out =MAX('+@xid+') from '+@tablename +
' where '+@yid + '=''' +@where+''''
exec sp_executesql @str, N'@out int output',@out output
end
go
----記得給字符型的變量加個引號(SQL兩單引號標示一個單引號)
begin
declare @str nvarchar(1000)
select @str = 'SELECT @out =MAX('+@xid+') from '+@tablename +
' where '+@yid + '=''' +@where+'''' PRINT @STR exec sp_executesql @str, N'@out int output',@out output
end
exec up_test 't_inlist','f_inid','f_drugid','000000',@out outputprint @out
declare @a int
exec up_test 'test_1' ,'a','b', '4',@a output
select @aCREATE TABLE [test_1] (
[id] [int] NULL ,
[a] [int] NULL ,
[b] [int] NULL
) ON [PRIMARY]
GO
exec p_get_XList_Max_XId 't_inlist','f_inid','f_drugid','000000',@out out结果:
SELECT @out =MAX(f_inid)as Maxid from t_inlist where f_drugid='000000'
服务器: 消息 156,级别 15,状态 1,行 1
在关键字 'as' 附近有语法错误。
select @output =max(xid) from ...... 是賦值語句
select max(xid) as maxid from ........ 才是查詢語句
create f up_test (@tablename varchar(256),@xid varchar(256),@yid varchar(256), @where varchar(800),@out int output)
as
begin
declare @str nvarchar(1000)
select @str = 'SELECT MAX('+@xid+') from '+@tablename +
' where '+@yid + '=''' +@where+''''
print @str
execute(@str)
end
go
照你说的:1:將@out 類型改為: varchar(50)
还是数据库中id项是'000001',结果却是'1'