How to write a SQL statement to have this scenario concluded | URGENT | IMPORTANT | PLEASE HELP

How to write a SQL statement to have this scenario concluded :-

IF A_NO = B_SERIAL_NO THEN A_NO + '-' + RIGHT(B_SERIAL_NO,4) ELSE A_NO + '-' + B_SERIAL_NO    --> populate to some Y in different table

Please help experts.

A_NO and B_SERIAL_NO are from the same table X
Jasmine SandlasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark WillsTopic AdvisorCommented:
do you want to create the new table Y, or update an existing columns ?

Start with making sure you are getting the correct values
SELECT CASE WHEN A_NO = B_SERIAL_NO THEN A_NO + '-' + RIGHT(B_SERIAL_NO,4) ELSE A_NO + '-' + B_SERIAL_NO END AS NEW_A_B_SERIAL_NO
FROM  [TABLE X]

Open in new window

Then once you are happy you can select that into a (temp) table by using SELECT ... INTO
SELECT CASE WHEN A_NO = B_SERIAL_NO THEN A_NO + '-' + RIGHT(B_SERIAL_NO,4) ELSE A_NO + '-' + B_SERIAL_NO END AS NEW_A_B_SERIAL_NO
INTO #Temp_Y         
FROM  [TABLE X]

-- then check out results 

SELECT * FROM #Temp_Y   

Open in new window

The target table when selecting INTO must not already exist.... It will be created.
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jasmine SandlasAuthor Commented:
thanks mark.. this is it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.