Hello,
I'm getting super frustrated, because I've looked at a lot, and can't seem to find anything that really says I can or can't.
Background: I am uploading a table that has 6500 rows & 153 columns. To do this, I make it a CSV file. In doing so, it removes leading 0s.
Out of these 153 columns, 15 or so have leading 0s of varying length.
What I would like to do - write a SP that checks the length of the string, adds appropriate amount of 0s. (I have written this)
The issue that I have, is that I would like to send in the column name as a variable so that I can just run the SP 15x instead of having to write out the code naming all 15 columns individually. Is there a way to do this?
When I name the column specifically, it changes 3500 rows-ish. When I change it to a variable, and send the column name, then it changes 0 rows.
This works:
BEGIN
update MyImport
set specificcolname = '0' + specificcolname
where LEN(specificcolname) = 5
update MyImport
set specificcolname = '00' + specificcolname
where LEN(specificcolname) = 4
update MyImport
set specificcolname = '000' + specificcolname
where LEN(specificcolname) = 3
update MyImport
set specificcolname = '0000' + specificcolname
where LEN(specificcolname) = 2
END
This does not work...
BEGIN
update MyImport
set @columnname = '0' + @columnname
where LEN(@columnname) = 5
update MyImport
set @columnname = '00' + @columnname
where LEN(@columnname) = 4
update MyImport
set @columnname = '000' + @columnname
where LEN(@columnname) = 3
update MyImport
set @columnname = '0000' + @columnname
where LEN(@columnname) = 2
END