No, it's not possible to build the query dynamically. It's a web application that uses BIRT (reporting tool).
Since I've found it really hard to construct and test queries in BIRT, I've been constructing/testing them in SS first. My current work around is to have 3 different reports that only differ in their ORDER BY... this works, but i thought it would be possible (and cleaner, easier to maintain) to combine the reports and have...
User Profile
Collapse
-
So, I can't SET the variable. This will be a parameter passed in from my application and I won't know what the value will be beforehand (and even though I only included one case, there will be multiple cases in my actual query).
The DECLARE does get rid of the error message but does not give me the right results. I am also getting an error message when I try to include more than 1 value in the ORDER BY:
Msg 102, Level...Leave a comment:
-
I'm testing this in SQL Server 2005, Management Studio.
Correct me if I'm wrong, but when you're just running a query in SS, you can just type the query, press 'Execute' and enter the parameters at that time, no? I'm confused because when I have a query with parameters in the SELECT or WHERE clause, it works perfectly fine.
[code=sql]SELECT *
FROM CALL
WHERE CALL.DESCRIPTIO N = @Param1[/code]
...Leave a comment:
-
I meant it to be a parameter that dynamically determines the ORDER BY. Since this is not a stored procedure, however, I don't know how to define the parameter before run time. Does this make sense?...Leave a comment:
-
Another question about case statements, now in ORDER BY.
Here is my query:
SELECT START_DATE, CALL_ID
FROM CALL
ORDER BY
CASE WHEN @OrderBy ='A' THEN START_DATE, CALL_ID
WHEN @OrderBy ='D' THEN START_DATE DESC, CALL_ID
WHEN @OrderBy ='R' THEN CALL_ID, START_DATE DESC
END
I looked up a bunch of articles and they seem to give...Leave a comment:
-
-
Sorry, I forgot my else statement in my sample code:
What I'm trying to do is set get the count of calls based on the parameter. The parameter determines whether call description is equal to 'In', 'Out', or 'Any'. If any, I want to view calls with description of 'In' or 'Out'.
So,
if @Param1 = 'In', then call.descriptio n = 'In'
if @Param1 = 'Out', then call.descriptio n = 'Out'
if @Param1 = 'Any'...Leave a comment:
-
problems with case statement in where clause
I was wondering if someone would be able to tell me what is wrong with my code here:
SELECT COUNT(*)
FROM CALL
WHERE CALL.DESCRIPTIO N =
CASE
WHEN @Param1 = 'In' THEN 'In'
WHEN @Param1 = 'Out' THEN 'Out'
END
I am getting an error that parameter is correct.
And just in case there is any confusion, I am taking in 1 parameter that is either going...
No activity results to display
Show More
Leave a comment: