sql server - Find string length in sql without starting of zero -


this question has answer here:

i have problem, uploading employee code , account number excel(.csv) file, , check employee code , update or insert account number corresponding employee code. if employee code start "0" csv file not consider 0's , send remaining character, when check in sql not match table data (employee code).

i have plan match them, don't know how do.

i have tried below query

declare @employeecodenet varchar(max)='mj300';  declare @employeecodedb varchar(max)='00mj300';   select ltrim(replace(@employeecodedb, '0', ''))--it should return 'mj300' 

if spaces not expected, close tried need:

declare @employeecodedb varchar(max)='00mj300';  select replace(ltrim(replace(@employeecodedb, '0', ' ')),' ','0') 

that is, replace 0s spaces, (ltrim) remove leading spaces, , replace spaces 0s (so, original 0s weren't in leading position reverted back)

result:

mj300 

if spaces may exist in string , they're not required, shouldn't magically turn 0s, can replace inner @employeecodedb yet replace: replace(@employeecodedb,' ','')


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -