Try using a CASE statement to get your results.  
Insert into yourtable (a, b, c)
SELECT    A = 
      CASE 
         WHEN price IS NULL THEN A
         WHEN price < 10 THEN B
         WHEN price >= 10 A
         ELSE C
      END,
   CAST(title AS varchar(20)) AS 'Shortened Title'
FROM titles
ORDER BY price

Syntax isn't pretty but you get the point
-----Original Message-----
From: Duane Boudreau [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 17, 2006 12:42 PM
To: SQL
Subject: SQL Question

Is there anyway of doing an if/else statement inside an insert clause,
something like?

 

 

Insert    dbo.myTable (x,y,z)

 

Select   dbo.myOtherTable.fieldA, dbo.myOtherTable.fieldB,

if (dbo.myOtherTable.fieldC != 0) dbo.myOtherTable.fieldC else
dbo.myOtherTable.fieldD

 

>From    dbo.myOtherTable

 

Where   dbo.myOtherTable.fieldN = 1

 

 

 






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:6:2432
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/6
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:6
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.6
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to