0
我想在動態查詢中使用in運算符。目前,我需要某人指出正確的方向,以便如何構造用於分隔值的撇號,以便它們不會干擾動態查詢結構的撇號。這是查詢中出現問題的一部分,所以我需要知道如何放置分隔符,以便所有值都可以包含在動態查詢格式中,而不是我現在使用的常規查詢格式。如何在動態查詢中使用IN運算符
WHERE ai.ImNumber != me.Company
AND me.ID IN ('value1','value2','value2','value3','value4','value5')'
我的查詢是
SET @SQLString = 'select me.EventID , ai.AggregateInfo, '''[email protected]+''' AS DateBegin, '''[email protected]+''' AS DateEnd
FROM tbl_MajorEarners me
INNER JOIN tbl_currentearners e ON e.EventID = me.EventID
INNER JOIN tbl_AggregateInfo ai ON ai.AggregateID = cs.ItemID
WHERE ai.ImNumber != me.CompanyNUmber
AND me.ID IN ('value1','value2','value2','value3','value4','value5')'
這是用於mysql還是sql-server? – ughai
添加您的問題的更多詳細信息?你會有最多5個動態值嗎?你的問題不清楚 – ughai
我正在使用sqlserver 2008,這是我的動態查詢 \t'SET @SQLString ='select me.EventID,ai.AggregateInfo, \t'''+ @ DateBegin +'''AS DateBegin,'' '+ @ EDateEnd +' '' AS DateEnd \t FROM tbl_MajorEarners我 \t INNER JOIN tbl_currentearnersË \t ON e.EventID = me.EventID \t INNER JOIN tbl_AggregateInfo艾 \t ai.AggregateID = cs.ItemID 其中,Ai .ImNumber!=我。公司紐約 AND me.ID IN('value1','value2','value2','value3','value4','val ue5')'' – anchor