Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to T-SQL Conditional calcualtion

Status
Not open for further replies.

vmon

IS-IT--Management
Feb 14, 2002
74
US
How would I do something like this in a T-SQL statement?
I have only done a little SQL and it was in Access.

I want to update a column in a temporary table called BegBalance to AmountSent if PreviousCollected is Null otherwise calcualte it as [Amount_Sent]-[PreviousCollected]-[PreviousAdjusted]

In Access I did it like this

BegBalance: IIf(IsNull([PreviousCollected]),[Amount_Sent],[Amount_Sent]-[PreviousCollected]-[PreviousAdjusted])

thanks,
vmon
 
Read in Books Online about the Case statement, it is SQL Server's replacement for the IIF command in Access
 
The folowing is query idea is from SQLsister's reply!

update BegBalance set previouscollected=(case when PreviousCollected is null then Amount_Sent
else [Amount_Sent]-[PreviousCollected]-[PreviousAdjusted] end)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top