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
 IF THEN CLAUSES

Author  Topic 

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 17:08:45
I'm importing a text field that is called advertiserTYPE. It will be one of four options in the parenthesis below:

advertiserTYPE (FSBO,BROKER,DEVELOPER,REALTOR) VarChar(50)

I need to be able to construct a statement that says something like:

If advertiserTYPE = FSBO
Then INSERT INTO [COLUMN1]
If advertiserTYPE = BROKER
Then INSERT INTO [COLUMN2
If advertiserTYPE = DEVELOPER
Then INSERT INTO [COLUMN3]

Am I on the right track??




tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-23 : 17:09:58
Well you insert into a table not a column. So what values are you going to put for the other columns in the table?

Tara Kizer
aka tduggan
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 17:22:08
Ok This is what I have:

-- Table BrokerType that I'm inserting into
INSERT INTO [DB1].[dbo].[BROKERTYPE]([IsFSBO], [FSBOName], [FSBOContact], [FSBOEmail], [FSBOWebsite], [FSBOLogo],[IsBroker], [BrokerageName], [BrokerageWebsite], [BrokerName], [BrokerImage], [BrokerContact], [BrokerLicence], [SalesPerLicense], [BDListingType], [BrokerageRelation], [BrokerCommission], [AppointmentNec], [IsDeveloper], [DeveloperName], [DeveloperContactName], [DeveloperContact], [DeveloperWebsite], [DeveloperImage], [isComplete])

-- I'm getting a text file thats going to say something like
advertisertype (FSBO or Broker or Developer or Realtor) varchar(50)
I need to put the type of advertiser for each record in text file into the appropriate column that I listed above. Does this help clarify? :)




Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-23 : 17:26:35
Providing a few rows of the file plus what the table should look like after the import (using those few rows) would help.

Tara Kizer
aka tduggan
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 17:30:30
I don't know what the table will look like after, b/c I havent done anything yet, and to be honest I dont have the text file yet either. I'm in the conceptual stages. I believe I need to use CASE expressions.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-23 : 17:31:43
If you don't have the table defined yet, then I'd suggest normalizing it.

You'll need to do some reading on normalization.
http://www.datamodel.org/NormalizationRules.html

Tara Kizer
aka tduggan
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 17:43:27
I don't need to normalize any data though b/c I'm not creating anything. I just need to insert records based on different criteria. I'm still researching case expressions.
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 18:13:27
Should look something like this but it's not working:

SELECT * =
CASE WHEN (SELECT [isFSBO],[FSBO)
WHERE [IsFSBO = 1]
THEN 'FSBO'
END
SELECT * =
CASE WHEN (SELECT [isFSBO])
WHERE [IsFSBO = 1]
THEN 'Realtor'
SELECT * =
CASE WHEN (SELECT [isFSBO])
WHERE [IsFSBO = 1]
THEN 'Developer'
FROM dbo.BrokerDeveloper
Go to Top of Page

gemispence
Yak Posting Veteran

71 Posts

Posted - 2006-02-23 : 18:27:28
I've cleaned it up a bit but still getting an error:

SELECT * =
CASE WHEN (SELECT [IsFSBO])
WHERE IsFSBO = 1
THEN 'FSBO'
CASE WHEN (SELECT [isBroker])
WHERE [IsBroker = 1]
THEN 'Broker'

ELSE 'Developer'

END
FROM dbo.BrokerDeveloper
Go to Top of Page
   

- Advertisement -