這裏就是我在與datetime
datetime和sp_executesql的
OPEN @form_dates
FETCH NEXT FROM @form_dates INTO @cid, @regdate, @compdate/* PRINT @regdate PRINT @compdate This is correctly having values in datetime. eg: Mar 28 2012 6:03PM PRINT @courseno */
WHILE @@FETCH_STATUS = 0 BEGIN SET @SQL = N'update tblname set cs' + CAST (@cid AS VARCHAR(10)) + '_begin = @rstring , cs' + CAST (@cid AS VARCHAR(10))+ '_end = @cstring where UserID = '+ CAST (@tempID AS VARCHAR(10))
DECLARE @ParmDefinition nvarchar(500) SET @ParmDefinition = N'@rstring datetime, @cstring datetime'
EXECUTE sp_ExecuteSQL @SQL, @ParmDefinition, @rstring = @regdate, @cstring = @compdate
I have the values of
@regdate
and@compdate
fetched from a cursor and are of the format Jan 3 2012 2:30PM Mar 28 2012 6:03PM but these values are not reflecting in procedure output where I get the output:update tblname set cs32_begin = @rstring , cs32_end = @cstring where UserID = 419
感謝我的問題,T-SQL代碼。^
歡迎使用StackOverflow:如果您發佈代碼,XML或數據樣本,**請**在文本編輯器中突出顯示這些行,然後單擊編輯器工具欄上的「代碼示例」按鈕(「{}」)格式和語法突出顯示它! –
請顯示'@SQL,@regdate和@ compdate'的定義,並解釋遊標和值來自哪裏的查詢。您要求我們徹底排除故障。 –
當你簡化的時候會發生什麼(例如我給出的例子,你只是'SELECT')?我也不明白你的意思是「這些值在程序輸出中沒有反映出來」 - 你如何在你的代碼樣本的最後一行得到輸出?你使用'PRINT @ SQL'嗎?如果是這樣,請記住,在使用'sp_executeSQL'後,'@ SQL'不會替換字符串中的值。 –