john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Sql query if no prod desc then use write in name

case expression
when value1 then result1
when value2 then result2

"searched case form"
case
when booleanexpression1 then result1
when booleanexpression2 then result2


first, get the quotedetailid data fields



if productdescription is NULL then prodpartno = productidname
else prodpartno = NULL





SELECT     quotedetailid,

CASE 
    WHEN    productdescription IS NULL THEN productidname 
    ELSE NULL 
    END AS prodpartno,

CASE 
    WHEN productdescription IS NULL 
    THEN
      (SELECT     FilteredProduct.new_productdescription
       FROM          FilteredProduct
       WHERE      FilteredQuoteDetail.productid = FilteredProduct.productid)

    ELSE productdescription

    END AS proddesc, quantity, priceperunit, baseamount, manualdiscountamount, extendedamount


FROM         FilteredQuoteDetail
WHERE     (quoteid = @QuoteId)


###########################################################
PERHAPS CLEANER / BETTER as this is just a simple IF statement!

CASE 
  WHEN productdescription IS NULL 
    THEN productidname

  WHEN productdescription IS NOT NULL 
    THEN productdescription

  ELSE NULL

END AS prodpartno,

(because productdescription is inaccessible for an Existing Product, so when productdescription contains data it must be the Write In Product name and appear in the produtpartno field area)


  • « microsoft crm 4 hash expired 0x8004A106
  • user session intro »

Published

Oct 26, 2010

Category

sql

~138 words

Tags

  • query 7
  • sql 18