February 28, 2008 at 5:37 am
I'm writting a query that get column name for selected tables.
SELECT
(SELECT c.column_name FROM information_schema.tables T
JOIN information_schema.columns C
ON t.table_name = c.table_name
WHERE t.table_type = 'base table' and t.table_name like 'L_%' )
INTO #TempTable FROM TableA A LEFT JOIN [Server-Name].DBName.dbo.TableB B ON A.ID = B.ID
How do I seperate the column name in my query so that they can have ',':D
February 28, 2008 at 9:58 am
DECLARE @Line VARCHAR(1000)
SET @Line = ''
SELECT @Line = @Line + c.column_name + ' , ' FROM information_schema.tables T
JOIN information_schema.columns C
ON t.table_name = c.table_name
WHERE t.table_type = 'base table' and t.table_name like 'L_%'
SELECT SUBSTRING(@Line, 1, LEN(@Line) -1)
It will give you a string of columns in the form of 'col1, col2, col3'
February 29, 2008 at 12:42 am
Thankx Loner. Its worked perfectly fine.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply