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?
 
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
 
Jasmine SandlasAuthor Commented:
thanks mark.. this is it
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.