I am trying to create a script that will return a fixed width column of only 35 characters and I want the resutls to have quotes around them. This is what I have so far right(((replace((Upper(Quotename(Table_name,'"'))),'','')))+ replicate('', 33 - LEN((Table_name) )),33)
The issue is that this script for lines with more than 35 characters does not show the quotes at the end.
Thank you soooo much for your help. I have been pulling my hair out trying to figure that script out. The script you suggested works perfectly the only issue I have now is that there is a space between the last character and the quote. How would I remove the extra space.
Thank you soooo much for your help. I have been pulling my hair out trying to figure that script out. The script you suggested works perfectly the only issue I have now is that there is a space between the last character and the quote. How would I remove the extra space.
Thank you
I thought you wanted to have the spaces padded if the length was less than 33. Or did you mean that you wanted the spaces AFTER the second double-quote. See the two examples in the code below. If it is neither, can you post sample output like I have done below?
CREATE TABLE #tmp(Table_Name VARCHAR(256));
INSERT INTO #tmp VALUES ('1234');
INSERT INTO #tmp VALUES ('1234567890123456789012345678901234567890');
-- Pads with spaces between the last character and the double-quote
-- if length is less than 33.
SELECT '"' + CAST(Table_Name AS CHAR(33)) +'"' FROM #tmp;
--"1234 "
--"123456789012345678901234567890123"
-- Pads with spaces after the last double quote
SELECT CAST('"' + CAST(Table_Name AS VARCHAR(33)) +'"' AS CHAR(35)) FROM #tmp;
-- There are trailing spaces after the first row below.
--"1234"
--"123456789012345678901234567890123"
DROP TABLE #tmp;