我已經寫在程序爲:有關SQL IN功能
create proc proc_sample
@emp_id as nvarchar(500)
as
begin
declare @sql as varchar(500)
set @sql='
select tdate,emp_id,
max(convert(varchar(40),DateDiff(minute,cast(tdate + ' ' +intime as datetime),
Cast(isnull(tdate_out,tdate) + ' ' +outtime as datetime))%(24*60)/60)+ 'hrs'+
convert(varchar(40),DateDiff(minute,cast(tdate + ' ' +intime as datetime),
Cast(isnull(tdate_out,tdate) + ' ' +outtime as datetime))%60)+ 'min')
as [Worked Hour],max(intime),max(outtime),max(inremarks)
from tbl_emp_attn_log
where emp_id in ('[email protected]_id+')and tdate
between '2010-1-01 00:00:00' and '2011-04-09 00:00:00'
group by tdate,emp_id order by emp_id,tdate'
end
但它顯示了以下錯誤:
Msg 170, Level 15, State 1, Procedure proc_sample, Line 10
Line 10: Incorrect syntax near ' +intime as datetime), Cast(isnull(tdate_out,tdate)+'.
,當我試圖解決這個問題,我不能讓我的願望的結果。所以任何一個在那裏解決這個
爲什麼你運行動態TSQL時,你似乎不需要這樣做? – 2011-05-16 06:31:13
很可能他在'@ emp_id'中使用逗號分隔empid。 – TheVillageIdiot 2011-05-16 06:32:59
@TheVillageIdiot:啊是的!錯過了那一點....然後將它們分解到一個臨時表並加入它。或者處理CSV ID值的許多其他方法之一 – 2011-05-16 06:42:54