question

khan16 avatar image
khan16 asked

sql query with field combination

I have this 2 fields SBSNBR, SEQNBR and I need to combine them into a 50 character length . The total records of the two fields will be 11 in total and I want the remaining to populated with zeroes. Blow is an example of expected output: characters are left justified so it would look like: 12345678900000000000000000000000000000000000000000000000000
sql 2008
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tom Staab avatar image Tom Staab ♦ commented ·
Can you please clarify what you are trying to do? Do you just want to concatenate the 2 numbers into a string? Can you give us some examples of data in the 2 fields and what output you want? Thanks.
0 Likes 0 ·

1 Answer

·
iainrobertson avatar image
iainrobertson answered
select left(cast(SBSNBR as varchar) + cast(SEQNBR as varchar) + replicate('0',50),50) from YourTable
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.