select query

Hi all,

Please find my attached select query, I am trying to use case statements in the select query to create new columns. Please correct my query.

Thanks in advance
parpaa  
select acno, datediff(dd,dateadd(dd,-19,[duedate]),getdate()) as deli,'over due'=case when
datediff(dd,dateadd(dd,-19,[duedate]),getdate())>19 then 'YES' else 'NO'
end ,'service line'= case when[subs]='*ISDN'then 'PRI' else '-' end,
'PRI'= case when
(case when[subs]='*ISDN'then 'PRI' else '-' end)
then 1 else 0
end
into t1 from tabel

Open in new window

parpaaAsked:
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.

DileepanCommented:
select acno, datediff(dd,dateadd(dd,-19,[duedate]),getdate()) as deli,
      'over due'=case when datediff(dd,dateadd(dd,-19,[duedate]),getdate())>19 then 'YES' else 'NO' end ,
      'service line'= case when[subs]='*ISDN' then 'PRI' else '-' end,
      'PRI'= case when (case when[subs]='*ISDN' then 'PRI' else '-' end) = 'PRI' then 1 else 0 end
into t1
from tabel
0
Rajkumar GsSoftware EngineerCommented:
SELECT  acno ,
        DATEDIFF(dd, DATEADD(dd, -19, [duedate]), GETDATE()) AS deli ,
        'over due' = CASE WHEN DATEDIFF(dd, DATEADD(dd, -19, [duedate]),
                                        GETDATE()) > 19 THEN 'YES'
                          ELSE 'NO'
                     END ,
        'service line' = CASE WHEN [subs] = '*ISDN' THEN 'PRI'
                              ELSE '-'
                         END ,
        CASE WHEN 'PRI' = ( CASE WHEN [subs] = '*ISDN' THEN 'PRI'
                                 ELSE '-'
                            END ) THEN 1
             ELSE 0
        END
INTO    t1
FROM    tabel

Open in new window

0

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
Anthony PerkinsCommented:
If I was to guess:
SELECT  acno,
        DATEDIFF(dd, DATEADD(dd, -19, [duedate]), GETDATE()) AS deli,
        CASE WHEN DATEDIFF(dd, DATEADD(dd, -19, [duedate]), GETDATE()) > 19 THEN 'YES'
             ELSE 'NO'
        END 'over due',
        CASE WHEN [subs] = '*ISDN' THEN 'PRI'
             ELSE '-'
        END 'service line',
        CASE WHEN [subs] = '*ISDN' THEN 1
             ELSE 0
        END 'PRI'
INTO    t1
FROM    tabel

Open in new window

0
LowfatspreadCommented:
this?
select acno,  deli
,'over due'=case when deli >19 then 'YES' else 'NO' end 
,'service line'= case when[subs]='*ISDN'then 'PRI' else '-' end
,'PRI'= case when[subs]='*ISDN' then 1 
   else 0 end
into t1 
from (select *
           , datediff(dd,dateadd(dd,-19,[duedate]),getdate()) as deli
      from tabel
     ) as x

Open in new window

0
parpaaAuthor Commented:
Thank you so much for your help. it worked
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
Microsoft SQL Server 2008

From novice to tech pro — start learning today.