Declare @tablename varchar(100)
set @tablename='temp_rep'
print @tablename
DECLARE @ColList Varchar(1000), @SQLStatment VARCHAR(1000)
SET @ColList = ''
select @ColList = @ColList + '[' +Name + ']'+ ' , ' from syscolumns
where id = object_id(@tableName) AND Name != 'vehicleid'
print @ColList
print Substring(@ColList,1,len(@ColList)-1)
SELECT @SQLStatment = 'SELECT ' + Substring(@ColList,1,len(@ColList)-1) + ' From ' + @tableName
print @SQLStatment
EXEC(@SQLStatment)
set @tablename='temp_rep'
print @tablename
DECLARE @ColList Varchar(1000), @SQLStatment VARCHAR(1000)
SET @ColList = ''
select @ColList = @ColList + '[' +Name + ']'+ ' , ' from syscolumns
where id = object_id(@tableName) AND Name != 'vehicleid'
print @ColList
print Substring(@ColList,1,len(@ColList)-1)
SELECT @SQLStatment = 'SELECT ' + Substring(@ColList,1,len(@ColList)-1) + ' From ' + @tableName
print @SQLStatment
EXEC(@SQLStatment)
No comments :
Post a Comment