• prathibha_aviator (10/29/2012)


    BriPan (10/28/2012)


    Try this One

    select

    * -- What ever column you want

    ,(case when Customer.CustomerID >3 then Order.PO else Order.OrderID end) as 'PO/OrderID'

    from

    Customer

    inner join CustomerOrders on Customer.CustomerID =CustomerOrders.CustomerID

    inner join Order on CustomerOrders.OrderID =Order.OrderID

    getting an error saying converting the field value 'verbal' to int is impossible... Why is it bothered about the datatypes of the same column when we r using select statement??? Select just returns the values right??

    It does but the values for a given column all have to in the same datatype. I am guessing here that OrderID is an int? This means that because of your case expression you are trying to return int and varchar data. It will attempt to convert to int because of datatype precedence. That means it will implicitly attempt to convert to int and the value 'verbal' will fail. To get around this you need to explicitly convert to a lower precendence (varchar). Instead of returning OrderID you will need to cast it as varchar. That help?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/