c***z 发帖数: 6348 | 1 It took me a whole day. Either I am retarded or SQL is. Why it is so
complicated just to loop over all columns!
I am posting here to help people facing similar problems. If you have a
better solution, please do share! Thanks!
Below is the SQL code:
DECLARE @ColName VARCHAR(150)
DECLARE @sqlStatement VARCHAR(MAX)
SET @sqlStatement = 'initial part of you query, for example select, insert
update etc. '
DECLARE myCursor CURSOR STATIC FOR
SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects
WHERE name = 'Your table name')
OPEN myCursor
FETCH NEXT
FROM myCursor
INTO @ColName
WHILE @@FETCH_STATUS = 0
BEGIN
-- build you query string here
-- from example:
-- set @sqlStatement = 'select' + ' ' + @ColName + ' ' + 'FROM
yourtablename'
SET @sqlStatement = 'select'
SET @sqlStatement = @sqlStatement + ' ' + @ColName + ' ' + 'FROM
yourtablename'
-- execute the query
EXEC(@sqlStatement)
FETCH NEXT
FROM myCursor
INTO @ColName
END
CLOSE myCursor
DEALLOCATE myCursor | m*******g 发帖数: 3044 | | c***z 发帖数: 6348 | 3 To pre-process data in SQL before modeling, which is supposed to be faster
than R...
【在 m*******g 的大作中提到】 : 收藏,太好了, 虽然看不懂. : 干啥用的?
| c***z 发帖数: 6348 | 4 Note: I didn't invent it, a co-worker taught me this
just to clarify |
|