读书人

SQL拼凑语句一个参数的写法。试了很

发布时间: 2013-04-02 12:35:26 作者: rapoo

SQL拼接语句,一个参数的写法。试了很多次试不出来。
日期型:(如2013-03-30)
@basic_date nvarchar(10)
date='''+convert(nvarchar(10),@date,121)+'''

字符型:
@name nvarchar(20)
name='''+@name+'''

数字型(int)的该怎么写呢?
[解决办法]

引用:
@number int
munber='+@number+'

给你个例子:

DECLARE @sql NVARCHAR(128)
DECLARE @int INT
SET @int=100
SET @sql='select top 1 * from sys.sysprocesses where spid<'+CONVERT (VARCHAR(10),@int)
EXEC (@sql)

/*
spid kpid blocked waittype waittime lastwaittype waitresource dbid uid cpu physical_io memusage login_time last_batch ecid open_tran status sid hostname program_name hostprocess cmd nt_domain nt_username net_address net_library loginame context_info sql_handle stmt_start stmt_end request_id


------ ------ ------- -------- -------------------- -------------------------------- ---------------------------------------------------------------------------------------------------------------- ------ ------ ----------- -------------------- ----------- ----------------------- ----------------------- ------ --------- ------------------------------ ------------------------------------------------------------------ -------------------------------------------------------- -------------------------------------------------------- ----------- ---------------- -------------------------------------------------------- -------------------------------------------------------- ------------ ------------ -------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------ ------------------------------------------ ----------- ----------- -----------
1 2324 0 0x015A 6347123 XE_DISPATCHER_WAIT
*/


[解决办法]
rtrim(@number)

读书人网 >SQL Server

热点推荐