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

SQL拼凑语句,一个参数的写法。试了很多次试不出来

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

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)

热点排行