笔记184 写的动态存储过程 sql论坛里的in() 怎麽传入参数问题

笔记184 写的动态存储过程 sql论坛里的in() 怎麽传入参数问题

 1 --写的动态存储过程 sql论坛里的in() 怎麽传入参数问题
 2 USE [pratice]
 3 GO
 4 /****** 对象:  StoredProcedure [dbo].[CT_CardType_Get]    脚本日期: 09/12/2012 00:00:42 ******/
 5 SET ANSI_NULLS ON
 6 GO
 7 SET QUOTED_IDENTIFIER ON
 8 GO
 9 /****** 对象:  StoredProcedure [dbo].[CT_CardType_Get]    脚本日期: 09/09/2012 22:16:06 ******
10 */    
11 ALTER PROCEDURE [dbo].[CT_CardType_Get]
12     (
13       @TargetValue1 INT ,
14       @TargetValue2 INT
15     )
16 AS
17     BEGIN
18         DECLARE @cdtsql NVARCHAR(4000)
19         SET @cdtsql = ' in(' + CAST(@TargetValue1 AS NVARCHAR(50)) + ','
20             + CAST(@TargetValue2 AS NVARCHAR(50)) + ')'
21   
22        
23   
24   
25         EXECUTE(' SELECT  * from   dbo.Orders   where  ProductID ' + @cdtsql)
26     
27     
28     END
29    
30    
31 ---------------------------------------------------------------------------------------
32 --测试
33    DECLARE @TargetValue1 INT
34    DECLARE @TargetValue2 INT
35    SELECT   @TargetValue1 = 700 ,
36             @TargetValue2 = 800
37  
38 
39    DECLARE @cdtsql NVARCHAR(4000)
40    SET @cdtsql = ' in(' + CAST(@TargetValue1 AS NVARCHAR(50)) + ','
41     + CAST(@TargetValue2 AS NVARCHAR(50)) + ')'
42   
43        
44   
45   
46    PRINT ( ' SELECT  * from   dbo.Orders   where  ProductID ' + @cdtsql )

 

posted @ 2013-08-04 12:56 桦仔 阅读(...) 评论(...)  编辑 收藏