So, my favorite time saver of all time:
create procedure [sp_get_columns] (@table nvarchar(255), @schema nvarchar(255) = ‘dbo’)
as
select stuff( (
select ‘, ’ + t1.Column_Name from information_schema.columns t1
where t1.Table_Name = @table and t1.TABLE_SCHEMA = @schema
for xml path (’’)),1,2,’’) as columns
will return results that look like so:
CASE_FCT_ID, CASE_BK, PTNT_DIM_ID, SRC_PTNT_ID, SRC_CARE_EVNT_CNTR_TXT, ANES_TP_DIM_ID, CASE_CRT_TS, CASE_STRT_TS
Problem: there’s often 50 or more columns. In my old age, I have started to love grouping my columns 5 per row, in 2 rows, then a space. I find this makes it easy to count columns and see that they match.
Question:
How would you manipulate the string get it to look like this:
col1, col2, col3, col4, col5,
col6, col6, col8, col9, col10,col11, col12, col13, col14, col15,
col16, col17, col18, col19, col20,col21, col22, col23, col34, col25,
col26, col27, col28, col29, col30