Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I have a following table, I want to add at the end of the string in naics coulumn '11' when its length is = 6, but it just adds 11 to the end of the number not increases the length:SELECT [hs],naics ,naics8_97 = CASE When len(naics)> 6 then naics when len(naics)<= 6 then naics +'11' else null end FROM [trade].[dev].[hs2naics8_import_2007]for example if I have nacis = 451277 I would like to make naics8_97 =45127711 but it returns 451288
DECLARE @naics int; SET @naics = 451277SELECT @naics, CASE WHEN len(@naics)> 6 THEN CAST(@naics AS varchar) ELSE CAST(@naics AS varchar) +'11' END AS naics8_97