Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2012-08-28 : 09:06:33
|
| sum(NegotiatedSellPrice+CancellationProtectionAmt) AS [Total Amount];or this line line in a query i want to add, if "iscancellationprotection" is "ÿes" else give only the value of negotiable price.ex: i have coloumsnegotiableprice>>>>cancellationproection>>>>cancellationprotectionamount1111>>>>>>>>>>>>>>>yes>>>>>>>>>>>>>>>>>>>>>>20222222>>>>>>>>>>>>>>>no>>>>>>>>>>>>>>>>>>>>>>>22123333>>>>>>>>>>>>>>>yes>>>>>>>>>>>>>>>>>>>>>>22024444>>>>>>>>>>>>>>>no>>>>>>>>>>>>>>>>>>>>>>>2222i want a new coloumn which adds "negotiable price" with "cancellationprotctionamount" only if iscancellationprotecion "yes".Please HelpThanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-08-28 : 09:13:48
|
[code]sum( NegotiatedSellPrice + case when iscancellationprotecion = 'yes' then CancellationProtectionAmt else 0 end) AS [Total Amount];[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-08-28 : 09:14:27
|
| case when cancellationproection = 'yes' then cancellationprotectionamount + negotiableprice else 0 endor maybecase when cancellationproection = 'yes' then cancellationprotectionamount + negotiableprice else negotiableprice end==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2012-08-28 : 09:39:16
|
| @ khtanMsg 170, Level 15, State 1, Line 7Line 7: Incorrect syntax near '='.Thanks |
 |
|
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2012-08-28 : 09:55:59
|
| this is my actual query::SELECT DATENAME(Year,BookingDate) as Year, DATENAME(Month,BookingDate) as Month,COUNT(InvoiceNumber) AS [Total Bookings], Sum(NegotiatedSellPrice) AS [Total Sale Price],sum( NegotiatedSellPrice + case when IsCancellationProtection = 'yes' then (CancellationProtectionAmt + NegotiatedSellPrice) else NegotiatedSellPrice endFROM tblInvoiceWHERE BookingDate >= '2006-01-01'AND BookingDate < '2020-02-01'AND fk_StatusID in (3, 5)GROUP BY DATENAME(Month,BookingDate) , DATENAME(Year,BookingDate),DATEPART(MM,BookingDate),DATEPART(YYYY,BookingDate)ORDER BY DATEPART(YYYY,BookingDate),DATEPART(MM,BookingDate)am getting an error Msg 156, Level 15, State 1, Line 9Incorrect syntax near the keyword 'FROM'.Please HelpThanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-08-28 : 10:10:18
|
[code]sum( NegotiatedSellPrice + (case when IsCancellationProtection = 'yes'then (CancellationProtectionAmt + NegotiatedSellPrice) else NegotiatedSellPrice end ) )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2012-08-29 : 01:18:07
|
| i HAVE A SYNTAX ERROR...CAN I USE LIKE INSTEAD OF =Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'YES' to a column of data type bit.CAN I USE :sum( (case when IsCancellationProtection LIKE 'YES'then ((CancellationProtectionAmt* SiteToSalesConvRate)+ NegotiatedSellPrice) else NegotiatedSellPrice end ) )AS [TOTAL SALES]Thanks |
 |
|
|
anuraag205
Yak Posting Veteran
58 Posts |
Posted - 2012-08-29 : 02:15:55
|
| I got what i wanted like this:::SELECT DATENAME(Year,BookingDate) as Year, DATENAME(Month,BookingDate) as Month,COUNT(InvoiceNumber) AS [Total Bookings], SUM (NegotiatedSellPrice) AS [Total NEGOTIABLE Sales],sum( ( case when IsCancellationProtection = '1'then ((CancellationProtectionAmt* (SiteToBaseConvRate/SiteToSalesConvRate))) else 0 end ) )AS [Total Cancellation Protection]FROM tblInvoiceWHERE BookingDate >= '2006-01-01'AND BookingDate < '2020-02-01'AND fk_StatusID in (3, 5)GROUP BY DATENAME(Month,BookingDate) , DATENAME(Year,BookingDate),DATEPART(MM,BookingDate),DATEPART(YYYY,BookingDate)ORDER BY DATEPART(YYYY,BookingDate),DATEPART(MM,BookingDate)Thanks you for your support ...:):):)Thanks |
 |
|
|
|
|
|
|
|