so simple sql query

1jaws
1jaws used Ask the Experts™
on
On select statement

if o.OrderID is not null
       '$' + convert(varchar, convert(money, inv.price * -1), 1) as amount
       else
       '$' + convert(varchar, convert(money, inv.price), 1) as amount

how can I write this logic  on tsql query?.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
DECLARE @results varchar(25)
if (select OrderID from Order
              where OrderID is not null)
SET @results =(select  '$' + convert(varchar, convert(money, inv.price * -1), 1) as amount From Order where OrderID is not null)
ELSE
SET @results =(select  '$' + convert(varchar, convert(money, inv.price), 1) as amount From Order where OrderID is not null)

select @results

Author

Commented:
I've requested that this question be deleted for the following reason:

dont need it

Commented:
i alrdeay shown example,how to do the logic in t-SQL, through that any one can understand how to process the logic in T-SQL.
11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Commented:
i alrdeay shown example,how to do the logic in t-SQL, through that any one can understand how to process the logic in T-SQL.
Systems Development / Support Specialist
Commented:
Select Case When o.OrderID is not null
       then '$' + convert(varchar, convert(money, inv.price * -1), 1)  
       else
       '$' + convert(varchar, convert(money, inv.price), 1) 
       End as amount

Open in new window

Author

Commented:
Sorry ukerandi, I didn't see your answer when I hit delete button. Thanks both for the answer.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial