A little something for the non technical people who would have had glazed eyes over the last post.
Saturday night I was out for my friend's hens night. I had consumed a few cocktails, as you do.
Got home and got ready for bed. Nudged wee Milly (my 35kg bullmastiff) off the sofa and she and I headed off to bed. She curled up on her half of the bed while I settled in with my iPad to catch up on twitter before drifting off to sleep. Suddenly, I was rudely awakened. Milly stood up, shook, huffed at me, stomped across me, jumped off the bed, and went to sleep on the sofa. I guess falling asleep on my back made my snoring a little loud and was keeping the poor princess up. :)
I think she might be a little spoiled. At least she didn't try to kick me off the bed.
Monday, March 28, 2011
Notes to self on XML PATH and String concatenation in t-sql for SQL2005, 2008 and beyond
Here's the query to be able to select the table name and get a concatenated list of the fields back. Very useful for generating queries on the fly.
SELECT
t.table_name,
STUFF((SELECT
', ' + column_name
FROM INFORMATION_SCHEMA.COLUMNS c where c.table_name = t.table_name
FOR XML PATH('')
), 1, 1, ''
) As concatenated_string
FROM INFORMATION_SCHEMA.TABLES t
WHERE table_name ='name_of_table'
I know it's not my usual type of post, but I keep forgetting the syntax and looking it up, so I put it where I 'll find it. :)
SELECT
t.table_name,
STUFF((SELECT
', ' + column_name
FROM INFORMATION_SCHEMA.COLUMNS c where c.table_name = t.table_name
FOR XML PATH('')
), 1, 1, ''
) As concatenated_string
FROM INFORMATION_SCHEMA.TABLES t
WHERE table_name ='name_of_table'
I know it's not my usual type of post, but I keep forgetting the syntax and looking it up, so I put it where I 'll find it. :)
Monday, March 07, 2011
February
Good bye. Can't say I'll miss you. I'm planning to spend next Feb in a hole somewhere blind drunk.
Subscribe to:
Posts (Atom)