Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270

    Unanswered: If Condition In Select Statement...

    Hi,
    I need to write an if condition in SELECT statement. Below is the code for the same. But its throwing error. Can some refine the code below.




    SELECT tblCustomer.Customer_LegalName,
    (IF (tblCustomer.IsNRACustomer = TRUE) SELECT tblCustomer.Customer_PassportNo ELSE
    ISNULL(tblCustomer.Customer_TaxId, tblCustomer.Customer_PassportNo))
    AS TAXID,

    tblCustomer.Customer_DoingBusinessAs, tblSeed_EDDCategory.CategoryName, '2' AS DCS, tblUser_OfficerCode.User_OfficerCode,
    tblCustomer.Customer_AreaId, tblCustomer.Customer_BranchId, CONVERT(VARCHAR(11), tblCustomer_EDDCategory.CreateDate)
    AS CreateDate, tblSeed_EDDCategory.EDDCategoryId, tblCustomer_EDDCategory.Category_CreateEmpId,
    tblCustomer_EDDCategory.CustCatId, tblCustomer.Customer_Id, tblSeed_Area.AreaName, tblSeed_Employee.Name,
    tblUser_OfficerCode.User_OfficerName, tblCustomer.Customer_TaxId, tblCustomer.IsNRACustomer,
    tblCustomer.Customer_PassportNo
    FROM tblCustomer INNER JOIN
    blCustomer_EDDCategory ON tblCustomer.Customer_Id = tblCustomer_EDDCategory.CustomerId INNER JOIN
    tblSeed_EDDCategory ON tblCustomer_EDDCategory.EDDCategoryId = tblSeed_EDDCategory.EDDCategoryId INNER JOIN
    tblSeed_Employee ON tblCustomer.Customer_CreateEmpId = tblSeed_Employee.EmployeeId INNER JOIN
    tblUser_OfficerCode ON tblCustomer.Customer_CreateEmpId = tblUser_OfficerCode.EmployeeId INNER JOIN
    tblSeed_Area ON tblCustomer.Customer_AreaId = tblSeed_Area.AreaId


    Thanks,
    Rahul Jha

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    It might help if you checked for the correct syntax in Books Online...
    Use a CASE statement int he SELECT clause:
    Code:
    SELECT	tblCustomer.Customer_LegalName,
    	case	tblCustomer.IsNRACustomer
    		when TRUE then tblCustomer.Customer_PassportNo
    		else ISNULL(tblCustomer.Customer_TaxId, tblCustomer.Customer_PassportNo)
    		end AS TAXID,
    	...
    ...but you are still going to have to define what "TRUE" is. What datatype is IsNRACustomer?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    Thanks Blindman :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •