Hi All,
As per project design we have to save the sql query in the database table (say, SQL_Table) and this query will be taken into execution at the runtime.
For example,
The Value_Table table design is as follows.
| BusD |
UnqId |
Value |
| 21/12/2007 |
1 |
300 |
| 21/12/2007 |
2 |
400 |
| 21/12/2007 |
3 |
100 |
| 22/12/2007 |
1 |
500 |
| 22/12/2007 |
2 |
600 |
| 22/12/2007 |
3 |
100 |
I should return the value, sum(Value) of UnqId in (1,2) - Value of UnqId in 3 for the particular BusD.
Looks simple? I am supposed save teh query with out the BusD condition. Bucase the BusD condtion ("and BusD=@BusD") will be added up with my saved query and will be executed after the concatination. (Confusing?!?!)
For example, forget about the minus in my calculation. I would save the following text in my SQL table.
"declare @Num float
select @Num=sum(Value) from Value_Table where UnqId in (1,2)"
My calculation sp, would aceept the @BusD and in the sp, we have hard coded. "and BusD=@BusD". The hardcoded string will be concatenated with my SQL_Table record. So, the executing statements will be,
declare @Num float
select @Num=sum(Value) from Value_Table where UnqId in (1,2) and BusD=@BusD. So, I will get the proper result in @Num and return the same.
Now my issue starts with minus value. I mean, sum(value) if UnqId in (1,2) - Sum(Value) if UnqId in (3). I have to write a single statement to achieve this. I dont know how to do that.
I hope, I explained my issue clearly.
Looking forward for the response.