在这里你去更新查询,由于缺乏信息,这是我能做的最好的事情,我相信没有像 Select [Select * from sample] From sample 这样的东西,你唯一能做的就是写你的动态查询正确并使用 sp_executesql 执行它,关闭因为你可以传递你的参数来过滤它,加油兄弟
declare @ExpressionString nvarchar(max)
set @ExpressionString = 'Select [No Column Name] From Sample'
EXECUTE sp_executesql @ExpressionString
2013-08-20 0930AM 下面是更新查询,试试吧=)
Declare @t1 TABLE
(
NAME NVARCHAR(MAX)
)
INSERT INTO @t1 VALUES ('Left(''AI 0400'',2)')
DECLARE @query NVARCHAR(MAX)
SET @query = 'Select ' + (SELECT NAME from @t1)
EXECUTE sp_executesql @query
2013-08-20 0950AM 这是另一个针对多列值的更新查询
Declare @t1 TABLE
(
NAME NVARCHAR(MAX)
)
INSERT INTO @t1 VALUES ('Left(''AI 0400'',2)')
INSERT INTO @t1 VALUES ('Left(''AI 0400'',2)')
INSERT INTO @t1 VALUES ('Right(''0000'' + ''AI 0400'',4)')
DECLARE @query NVARCHAR(MAX)
DECLARE @nTotalRec INT
SET @nTotalRec =(SELECT COUNT(NAME) FrOM @t1) +1
DECLARE @nCount INT
SET @nCount = 1
DECLARE @Condition NVARCHAR(MAX)
SET @Condition = ''
WHILE @nCount !=@nTotalRec
BEGIN
SET @Condition = @Condition + (
SELECT NAME FROM (
SELECT NAME,Rn = ROW_NUMBER() OVER (ORDeR BY NAME) FROM @t1) q
WHERE Rn = @nCount) + ','
SET @nCount = @nCount +1
END
SET @Condition = LEFT(@Condition,LEN(@Condition)-1)
SET @query = 'Select ' + @Condition
EXECUTE sp_executesql @query