如题所述
1.EXECç使ç¨
EXECå½ä»¤æ两ç§ç¨æ³ï¼ä¸ç§æ¯æ§è¡ä¸ä¸ªåå¨è¿ç¨ï¼å¦ä¸ç§æ¯æ§è¡ä¸ä¸ªå¨æçæ¹å¤çã以ä¸æ讲çé½æ¯ç¬¬äºç§ç¨æ³ã
ããä¸é¢å 使ç¨EXECæ¼ç¤ºä¸ä¸ªä¾å,代ç 1
DECLARE @TableName VARCHAR(50),@Sql NVARCHAR (MAX),@OrderID INT;
SET @TableName = 'Orders';
SET @OrderID = 10251;
SET @sql =
ãããã'SELECT * FROM '+QUOTENAME(@TableName) +'WHERE OrderID = '+
ããããCAST(@OrderID AS VARCHAR(10))+' ORDER BY ORDERID DESC'
EXEC(@sql);
sp_executesqlå½ä»¤å¨SQL Serverä¸å¼å ¥çæ¯EXECå½ä»¤æä¸äºï¼å®ä¸»è¦ä¸ºéç¨æ§è¡è®¡åæä¾æ´å¥½çæ¯æã
为äºåEXECä½ä¸ä¸ªé²æç对æ¯,æ们ççå¦æç¨ä»£ç 1ç代ç ï¼æEXECæ¢æsp_executesql,ççæ¯å¦å¾å°æ们æææçç»æ
DECLARE @TableName VARCHAR(50),@sql NVARCHAR(MAX),@OrderID INT ,@sql2 NVARCHAR(MAX);
SET @TableName = 'Orders ';
SET @OrderID = 10251;
SET @sql = 'SELECT * FROM '+QUOTENAME(@TableName) + ' WHERE OrderID = '+CAST(@OrderID AS VARCHAR(50)) + ' ORDER BY ORDERID DESC'
EXEC sp_executesql @sql
EXECå½ä»¤æ两ç§ç¨æ³ï¼ä¸ç§æ¯æ§è¡ä¸ä¸ªåå¨è¿ç¨ï¼å¦ä¸ç§æ¯æ§è¡ä¸ä¸ªå¨æçæ¹å¤çã以ä¸æ讲çé½æ¯ç¬¬äºç§ç¨æ³ã
ããä¸é¢å 使ç¨EXECæ¼ç¤ºä¸ä¸ªä¾å,代ç 1
DECLARE @TableName VARCHAR(50),@Sql NVARCHAR (MAX),@OrderID INT;
SET @TableName = 'Orders';
SET @OrderID = 10251;
SET @sql =
ãããã'SELECT * FROM '+QUOTENAME(@TableName) +'WHERE OrderID = '+
ããããCAST(@OrderID AS VARCHAR(10))+' ORDER BY ORDERID DESC'
EXEC(@sql);
sp_executesqlå½ä»¤å¨SQL Serverä¸å¼å ¥çæ¯EXECå½ä»¤æä¸äºï¼å®ä¸»è¦ä¸ºéç¨æ§è¡è®¡åæä¾æ´å¥½çæ¯æã
为äºåEXECä½ä¸ä¸ªé²æç对æ¯,æ们ççå¦æç¨ä»£ç 1ç代ç ï¼æEXECæ¢æsp_executesql,ççæ¯å¦å¾å°æ们æææçç»æ
DECLARE @TableName VARCHAR(50),@sql NVARCHAR(MAX),@OrderID INT ,@sql2 NVARCHAR(MAX);
SET @TableName = 'Orders ';
SET @OrderID = 10251;
SET @sql = 'SELECT * FROM '+QUOTENAME(@TableName) + ' WHERE OrderID = '+CAST(@OrderID AS VARCHAR(50)) + ' ORDER BY ORDERID DESC'
EXEC sp_executesql @sql
温馨提示:答案为网友推荐,仅供参考