saquib.waheed Posted July 23, 2013 Share Posted July 23, 2013 Hello, I have declared two string variables in iReport qurey designerDECLARE @str nvarchar(max), @str1 nvarchar (max);Select @str = ' AND (BondSales_Confirmed <> -1) ', @str1 = ' AND (BondSales_IssueType = ''REGULAR'') ';Now, If I try to execute a query like following:SELECT * from t_BondSales WHERE (BondSales_cType <> 'Institute') +@str + @str1It shows me following error:Error: SQL Problems: Incorrect Syntax near '+'Can anyone please suggest me what is the proper syntax to concatenate string variables in WHERE clause? I can do this in SQL Server 2008 R2, but how to do it in Jasper?In SQL Server, I've done something like this:DECLARE @sql NVARCHAR(MAX)Select @sql = 'SELECT * from t_BondSales WHERE (BondSales_cType <> 'Institute')' +@str + @str1EXEC sys.sp_executesql @sql //**This line executes the queryBut I guess, I can not do that in iReport... What should I do? Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 23, 2013 Share Posted July 23, 2013 Hi, Probably you cannot use a variable directly in the query,you will have to make use of parameter . Please describe as to what you want to do so that I can help you better Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
saquib.waheed Posted July 23, 2013 Author Share Posted July 23, 2013 HI Ankur, I've tried several times to update my question, but the server isn't allowing me to do this. It shows that, the document is locked and I can't edit that :( Whenever it allows me, I'll update my question. Thanks Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 23, 2013 Share Posted July 23, 2013 You can add right here in a comment or can add again question with the description Link to comment Share on other sites More sharing options...
saquib.waheed Posted July 23, 2013 Author Share Posted July 23, 2013 Hi Ankur, I edited my question. If you can, please check and suggest me if you have any solution to that. Thanks Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 23, 2013 Share Posted July 23, 2013 Hi,Instead of using variables what you can do is that you can create two parameters and define the same two values as the default values of the two parameters$P{param1} = "AND (BondSales_Confirmed <> -1)", $P{param2}= " AND (BondSales_IssueType = 'REGULAR') "remember don't check the option use as prompt for the parameters as we have to use the defualt values defined above onlyand in the query you can simply put this SELECT * from t_BondSales WHERE (BondSales_cType <> 'Institute') AND P!{param1} AND P!{param2} This will work.Please check the sameHope that above explanation helps you. Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
saquib.waheed Posted July 23, 2013 Author Share Posted July 23, 2013 Thanks for the reply Ankur. I've tried your way but somehow, couldn't succeed. So, I tried another way through SQL Server and now it is working. I really appreciate your effort. Link to comment Share on other sites More sharing options...
pssp25 Posted August 22, 2013 Share Posted August 22, 2013 Hi Saquib,The Concatenate function depends on the SQL engine that you are using.Which Database are you using for your reports?I think that condition that your are trying to test can be solve with :WHERE NOT IN ('val1','val2','val3') Hope it helps,Kind regards,Paulo Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now