Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using case statement with into command

Author  Topic 

kdjonesmtb
Starting Member

3 Posts

Posted - 2012-06-01 : 11:11:39

I wanted to do something like this but sql does not like the syntax


case when datasource ='QNXT'
then

into #QNXT_Source_data


I can just clone the code multiple times but it seems redundant


Thanks

--QNXT table creation
--drop table #QNXT_Source_data
SELECT nationalproviderid,providerid,datasource,providername
,NameLast
,NameFirst
,NameMiddle
,NameSuffix
,FederalTaxId
,Gender
,BirthDate
,Ethnicity
,Languages
,ProviderType
,MailingAddress1
,MailingCity
,MailingState
,MailingZipCode
,MailingCounty
,PhysicalAddress1
,PhysicalCity
,PhysicalState
,PhysicalZipCode
,Phone
,PrimarySpecialty
,CLIANumber
,DEANumber
,StateOfMassachusettsLicense

case when datasource ='QNXT'
then


into #QNXT_Source_data

FROM DW.DBO.PROVIDERDEMOGRAPHICS PD
WHERE NationalProviderId in

(SELECT nationalproviderid

--FROM
----(SELECT count(*) as countof,nationalproviderid
FROM DW.DBO.PROVIDERDEMOGRAPHICS PD
WHERE NationalProviderId <> '')


Keith David Jones Senior Business Analyst

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-01 : 11:14:57
Can you describe what you are trying to do in words? Is that a conditional insert? If so, you could use dynamic sql or you'll have to break it into two separate statements: SELECT and INSERT.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-01 : 11:58:04
quote:
Originally posted by kdjonesmtb


I wanted to do something like this but sql does not like the syntax


case when datasource ='QNXT'
then

into #QNXT_Source_data


I can just clone the code multiple times but it seems redundant


Thanks

--QNXT table creation
--drop table #QNXT_Source_data
SELECT nationalproviderid,providerid,datasource,providername
,NameLast
,NameFirst
,NameMiddle
,NameSuffix
,FederalTaxId
,Gender
,BirthDate
,Ethnicity
,Languages
,ProviderType
,MailingAddress1
,MailingCity
,MailingState
,MailingZipCode
,MailingCounty
,PhysicalAddress1
,PhysicalCity
,PhysicalState
,PhysicalZipCode
,Phone
,PrimarySpecialty
,CLIANumber
,DEANumber
,StateOfMassachusettsLicense

case when datasource ='QNXT'
then


into #QNXT_Source_data

FROM DW.DBO.PROVIDERDEMOGRAPHICS PD
WHERE NationalProviderId in

(SELECT nationalproviderid

--FROM
----(SELECT count(*) as countof,nationalproviderid
FROM DW.DBO.PROVIDERDEMOGRAPHICS PD
WHERE NationalProviderId <> '')


Keith David Jones Senior Business Analyst


Case is not a conditional statement using which you can manipulate sequence flow of execution but its just an expression which returns value of field conditionally
I think what you may be looking would be IF..ELSE statement but again for that you need separate SELECT statements

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -