Correct my query

Dear Experts,

I have discomfort with my select query ( pls find it below) I know it is wrong..
I highly appreciate if you could correct it.. thanks in advance
select account_no, case 
when [del_no]=0 to 8 then ( select [days_0_8] from table2)
when [del_no]=9 to 15 then ( select [days_9_15] from table2)

end as 'del'
into table3 from table1

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.

ambidextrousCommented:
Would this work for you?

SELECT DISTINCT
  a.Account_No
 ,CASE
    WHEN a.del_no BETWEEN 0 AND 8 THEN b.[days_0_8]
    WHEN a.del_no BETWEEN 0 AND 15 THEN b.[days_9_15]
  END as [del]
INTO table3
FROM      table1 a, table2 b
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
dwe761Software EngineerCommented:
I think we'll need a little more info about the relation between table1 and table2, because if you select all rows of column [days_0_8] every time table1.[del_no] is between 0 to 8, you'll end up with lots of duplication.

Maybe an example of data going in would be helpful and the outcome you'd expect.
0
parpaaAuthor Commented:
thnks for soln .. It resolved.
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.