Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Case Statement

$
0
0

I have a scenario where I have four column and different rules to pick up a field... The table is like this

        AII                AI2                             CS1                                  CS2                                        FROM                                  TO

From-LHR         TO- MPG                     TAX reim                          TAX TRue    

From-PMR         TO- MPG                    TAX reim                          TAX FILE

From-                  TO-                            From-BAN                     To-ND

From-9/12          To-9/13                      Tax Reim                       TAx up

From-9/12              To-9/13                     From-NP                    To-KPP           

From-DAl<->NY       To-NY<-> DAL           Tax Reim                 TAx up           

So I have a  data that comes in a really weird Fashion so what I need to do is  below.(My output that I am expecting).....

 AII                      AI2                       CS1                          CS2               FROM                  TO

From-LHR           TO- MPG                 TAX reim                   TAX TRue                LHR                  MPG
 
From-PMR            TO- MPG                 TAX reim                    TAX FILE               PMR                  MPG

From-                    TO-                      From-BAN                   To-ND                 BAN                   ND

From-9/12           To-9/13                  Tax Reim                   TAx up                 Unknown           Unknown

From-9/12            To-9/13                  From-NP                    To-KPP                 NP                      KP

From-DAl<->NY    To-NY<-> DAL       Tax Reim                   TAx up                 Unknown               Unknown   

So basicalley I need to compare first two rows and see if it has letter  then use that else use from CS1 and CS2 but if it have dates/numbers  then select from CS1 and CS2. I beleive the output is self explanatory. Any suggestions???

I have more than a million rows so I dont want to do manually for each line so was really looking for some logic I can apply to update my table...Any help is appreciated...


SPPandey






Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>