Programmatically setting SQL Query string?
Post Author: JoeM
CA Forum: Data Connectivity and SQL
Hi,
I recently updated to Crystal Reports 11 from 8.5 and am having some problems getting my reports to properly function. I need to set the SQL query string in the report at runtime in our C++ based program when the user selects what report they want to print. So to do this I first open the report and connect to our database and that works fine, here is the code for that -
pReport = pCRPApp->OpenReport(TmplFName, dummy) ;
pReport ->Database->LogOnServer("crdb_odbc.dll", ODBC_FILEDSN, DatabaseName, DatabaseUsrNm, DatabasePwd);
but when I use PutSQLQueryString to set the custom sql query that I've made it does not appear to work because when I use GetSQLQueryString right after that, the returned string is not the one I just set. Here is the code for that part -
pReport->PutSQLQueryString(SQLExprBuf);
sprintf(TestSQL, pReport->PutSQLQueryString());
TestSQL is not the same as SQLExprBuf
So my question is how do I properly set the SQL query string programmatically, is there some setting in my report that needs to be turned on or am I using the wrong function? I read somewhere that you can use the Add command option in the report to set the query string as well, is there a way to programmatically do that?
In Access create a View showing the information you want, then in design mode click View, SQL to see teh SQL you need. now make sure the SQL you build in VBA is exactly the same. so in the Immediate window type a ? then copy paste your code then press Enter
to see the result, EG:
?"UPDATE Lan_landmeter " _
& "SET OpleidingsBedrijf =" & bedrijf & " ,Opleiding_startdatum =#" & startdatum & "#,Opleiding_einddatum =#" & einddatum & "#,Aantal_opleidingsuren_vast=20,Aantal_gevolgde_uren
=" & gevolgde_uren & ",Aantal_resterende_uren=0" _
& "WHERE Id_landmeter =" & naam & ""
Rod Gill
Author of the one and only Project VBA Book
www.project-systems.co.nz
Similar Messages
-
Overflow the SQL query string buffer
Hello,
I have a report that is using a query to determine values for a parameter. In Report Builder everything renders fine, but when I publish the report on the Report Server, it will not render if too many values are entered for the parameter, including "Select
All". The reason for this behavior is likely due to the number of possible values for the parameter being over 2500. My research has shown that this is causing an overflow of the SQL query string buffer. The obvious fix is to not use that column as a
parameter, but the power that be are insisting. My system administrator says he can likely increase the buffer size, but has asked me to find out how and where to do that. Any help would be much appreciated.Hi CrazyAlligator,
According to your description, you have more than 2500 values within a parameter. It throws overflow exception when selecting all values. Right?
Microsoft security update MS11-100 limits the maximum number of form keys, files, and JSON members to
1000 in an HTTP request. Because of this change, ASP.NET applications reject requests that have more than
1000 of these elements. HTTP clients that make these kinds of requests will be denied, and an error message will appear in the web browser. The error message will usually have an HTTP 500 status code. This new limit can be configured on a per-application
basis. Please see the "Resolution" section for configuration instructions. Please refer the KB article:
https://support2.microsoft.com/kb/2661403?wa=wsignin1.0
In this scenario, we need add the setting in the web.config file. Please follow the steps below:
Go to the reporting services installation folder.
Go to the report server folder and make a backup of the file “Web.config”. Once you have the backup, open the original file in notepad and add the following entry under the Configuration section:
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="10000"/>
</appSettings>
Go to the Report Manager folder and again make a backup of the file “Web.config”. Once you have the backup, open the original file in notepad and add the following entry under the appSettings tag:
<add key="aspnet:MaxHttpCollectionKeys" value="10000"/
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .
Hi Srinath,
The below blog might be useful
http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
regards,
Harish -
Hi,
I would like to konw how I can make multiple parameters to sql query string seperated by ,(comma) ..
For example, this parameters can be printed like 'abc,dde,ggf,eeg' ,once I use "join(Parameters!rpCode.Value,",")" with report builder ,
By the way, when I test this multiple parameters by Query Designer of report builder there was no problem,.(using Define query parameters, I put abc,dde,ggf,eeg)
however, when I run this report , it won't be executing , with (rsErrorExecutingCommand)
Plz, help me....If its sql query then it should like this
Select t.*
from table t
inner join dbo.ParseValues(@Parameters,',')f
on f.val = t.ID
ParseValues can be found him
http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
or easier way is
Select t.*
from table t
where ',' + @Parameters + ',' LIKE '%,' + CAST(t.ID AS varchar(10)) + ',%'
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
SQL Query string in VBA Access 2010
Hi everyone,
I am writing sql queries in VBA Access 2010.
Now, i am very new to VBA programming, so i don't know how i have to write te string for the query.
I mean, are the " a,d _& sings in the good place?
The query sits behind a button on the form and when i use the form and click on the button i get the following error
This is the code i wrote:
Option Compare Database
Option Explicit
Private Sub Knop9_Click()
Dim bedrijf As String
Dim startdatum As Date
Dim einddatum As Date
Dim aantal_uren_jaarlijks As Double
Dim gevolgde_uren As Double
Dim resterende_uren As Double
Dim naam As String
'Voeg de waarden die ingevuld werden in het form in de variabelen
Tekst1.SetFocus
bedrijf = Tekst1.Text
Tekst3.SetFocus
startdatum = Tekst3.Text
Tekst5.SetFocus
einddatum = Tekst5.Text
Tekst7.SetFocus
gevolgde_uren = Tekst7.Text
Tekst11.SetFocus
naam = Tekst11.Text
CurrentDb.Execute "UPDATE Lan_landmeter " _
& "SET OpleidingsBedrijf =" & bedrijf & " ,Opleiding_startdatum =#" & startdatum & "#,Opleiding_einddatum =#" & einddatum & "#,Aantal_opleidingsuren_vast=20,Aantal_gevolgde_uren =" & gevolgde_uren & ",Aantal_resterende_uren=0" _
& "WHERE Id_landmeter =" & naam & ""
CurrentDb.Close
End Sub
Did i wrote the query string right?
ThxIn Access create a View showing the information you want, then in design mode click View, SQL to see teh SQL you need. now make sure the SQL you build in VBA is exactly the same. so in the Immediate window type a ? then copy paste your code then press Enter
to see the result, EG:
?"UPDATE Lan_landmeter " _
& "SET OpleidingsBedrijf =" & bedrijf & " ,Opleiding_startdatum =#" & startdatum & "#,Opleiding_einddatum =#" & einddatum & "#,Aantal_opleidingsuren_vast=20,Aantal_gevolgde_uren
=" & gevolgde_uren & ",Aantal_resterende_uren=0" _
& "WHERE Id_landmeter =" & naam & ""
Rod Gill
Author of the one and only Project VBA Book
www.project-systems.co.nz -
Programmatically set af:query attributes value
Hello,
Is there an option to programmatically execute af:query search giving some attributes value?
I have a query component for the view criteria like:() Group
Attrib1 =
AND Attrib2 =
AND Attrib5 =There are almost 30 attributes in this VO that can be used in a query with advanced search mode, so I wouldn't like to create 30 bind variables for them (not sure that would be a solution either).
Maybe there are some methods in QueryModel or QueryDescriptor to archieve this?
// set some attributes in a key/value style
query.setAttribute("AttribX", 123);
// execute query
JSFUtils.resolveMethodExpression("#{bindings.InformationSearchVCQuery.processQuery}", null,
new Class[] { QueryEvent.class }, new Object[] { queryEvent });Thanks.
ADF 11.1.2.2You can use something like this to iterate through VC and set values:
http://adf-code-corner.blogspot.com/2012/08/programmatically-changing-validation.html
Dario -
Set whole Query string to null or ""
Good morning!
Is there a way to set the whole query string to null or ""?
so that request.getQueryString() = "" ?
I've been trying something like this
String body = "";
request.setAttribute(???, body);
what would go in the ???
thanks,
AlexThats not good. I'm having a problem when the session times out. When a person times out , the system forwards them to the login screen. When they login, they are authenticated by siteminder and the last action they requested is sent (whatever is in the querystring) The querystring tries to go to our controllerservlet (in the querystring), and bypasses the login servlet! I figured if you set toe querystring to "", it would have to go to the loginservlet
-
Explicitly setting the query string in http get request
Hi All,
We are trying to use the query string parameter to send a GET request to a vendor. The parameter value is a string concatenated with xml ie. String=<xml></xml> It seems the vendor is reading this value as string and Looking for "<XML>" to strip out the values. The problem in OSB is when I concatenate the fn:concat("String=",<XML/>) the acutal value is translated to "String=<XML/>. Is there a way to explicitly set the value so the < doesn't get encoded to < ? the odd thing is that only the left less than bracket get encoded. Any help would be most appreciated...
thanks,
Matt
version of OSB:
Service Bus 10gR3
Oracle Service Bus Version: [WebLogic Oracle Service Bus 10.3 Sat May 30 06:12:38 EDT 2009 1223943 ]
Oracle Weblogic Server Version: [WebLogic Server 10.3 Fri Jul 25 16:30:05 EDT 2008 1137967 ]The left side bracket is actually getting encode as amplt; (this forum encoded it :))
-
How to display report from SQL query string
<p>I am a new user at this forum, my name is Muneer.</p><p>I have a doubt please help me</p><p>I am develoing an Institute Management System (Plat form VB.Net 2003), that can add participant details, course details, Account details so and so....</p><p>my problem is i have a VB.net form ,that form include combo box and flex grid.</p><p>when i select a text from combobox, data will be display in flexgrid its ok. but i want same out in Report.</p><p>when i try to make it showing all data please help me asap. how can i pass data to report.</p><p>I am using ADODB.Connection method with Access Database.</p><p>waiting ur valuable reply</p><p>Muneer</p>
This sample passes ado data to a report.
[http://diamond.businessobjects.com/node/2052Â | /node/2052]
Rob Horne
Rob's blog - http://diamond.businessobjects.com/blog/10</p> -
Set query string programmatically
Is there a way to set the query string of a report programmatically at runtime? Something like clientDoc.setQueryString( query ).
ThanksWell, it's not too complex to do it with java... here is a simple example:
public class QueryStringChanger
public static String changeParameter(String query, String key, String value)
String[] keyValuePairs = query.split("&");
StringBuffer newQuery = new StringBuffer();
for (int k = 0; k < keyValuePairs.length; k++)
if (keyValuePairs[k].indexOf(key) != -1)
String[] thePair = keyValuePairs[k].split("=");
keyValuePairs[k] = thePair[0] + "=" + value;
if (k != 0) newQuery.append("&");
newQuery.append(keyValuePairs[k]);
return newQuery.toString();
public static void main(String[] args)
if (args.length != 3)
System.out.println("Syntax: java QueryStringChanger 'the query string' theKey theValue\n"+
"Example: java QueryStringChanger page=1&area=3&title=Not+So+Good title Pretty+Darn+Good");
System.exit(1);
System.out.println(changeParameter(args[0], args[1], args[2]));
System.exit(0);
}Not so sure what you would gain from a HashTable though... -
Need Help in Splitting a String Using SQL QUERY
Hi,
I need help in splitting a string using a SQL Query:
String IS:
AFTER PAINT.ACOUSTICAL.1..9'' MEMBRAIN'I would like to seperate this string into multiple lines using the delimeter .(dot)
Sample Output should look like:
SNO STRING
1 AFTER PAINT
2 ACOUSTICAL
3 1
4
5 9" MEMBRAIN
{code}
FYI i am using Oracle 9.2There's this as well:
with x as ( --generating sample data:
select 'AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN' str from dual union all
select 'BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN' str from dual)
select str,
row_number() over (partition by str order by rownum) s_no,
cast(dbms_xmlgen.convert(t.column_value.extract('//text()').getstringval(),1) as varchar2(100)) res
from x,
table(xmlsequence(xmltype('<x><x>' || replace(str,'.','</x><x>') || '</x></x>').extract('//x/*'))) t;
STR S_NO RES
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 1 AFTER PAINT
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 2 ACOUSTICAL
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 3 1
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 4
AFTER PAINT.ACOUSTICAL.1..9" MEMBRAIN 5 9" MEMBRAIN
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 1 BEFORE PAINT
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 2 ELECTRIC
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 3 2
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 4
BEFORE PAINT.ELECTRIC.2..45 caliber MEMBRAIN 5 45 caliber MEMBRAIN
{code} -
How can I use today's date as default value in query string filter web part in SharePoint
I have a query string filter on my web part page. I am trying to figure out how I can set it's default value to Today? I can't find anything online...
Hi,
Per my understanding, you might want to set a default value to the Query String Filter Web Part.
It would not be able to set default value to the Query String Filter Web Part with the OOTB features available.
By default, with a Query String Filter Web Part in the current page, we can filter other web part in the same page by adding parameters and values in the address bar
of browser.
If setting the “Query String Parameter Name” of a Query String Filter Web Part as “t”, then we can filter the corresponding connected web part by inputting such an
URL into the address bar:
http://sharepoint/SitePages/Page1.aspx?t=value1
Suppose you want to filter the list view with a value dynamically when user opens this page, as a workaround, we can generate an URL with the parameters needed when
page loaded, then redirect user to this URL afterwards. This can be achieved using JavaScript.
About how to redirect user to other page with an URL:
http://www.tizag.com/javascriptT/javascriptredirect.php
How to get today’s date using JavaScript:
http://www.w3schools.com/js/js_dates.asp
Best regards
Patrick Liang
TechNet Community Support -
Hi, is there a way to set sql query for a column?
the query should take value from column in the table.
in my case, it has come down for a need to have a nested select query inside my query:
select app.application_id,
(SELECT LISTAGG(typ.verification_name, ', ') WITHIN GROUP (ORDER BY typ.verification_id) FROM
typ,chk where
chk.application_id = app.application_id
GROUP BY app.application_id ) AS verification_type,
from tablea,tableb where....
<note that application_id is coming from the bigger query , aka another column from another table.>
i've tried
CAST ( EVALUATE_AGGR('LISTAGG(%1,%2) WITHIN GROUP (ORDER BY %3 DESC)', "typ"."verification_name", ', ', "chk "."application_id ") AS CHARACTER ( 50 ))
but my query need more than few EVALUATE_AGGR resulting in huge query in the log plus it's hard to put more details from other tables when you do this since everything buble down to the group by in the end of the query.
pls help if there's something even close to thisHi jan ,
thanx for your interest but let me clear with my requirement. What I want to do is that after executing the view query I want to navigate through records and sets some property or a group of property ( think it as a java object which holds properties ) for that cell and after that when I Navigate through record I don't want to run my logic for calculating properties again and I should be able to get those properties which I set earlier. There can be any number of records and most of time value will remain same then why should I calculate properties every time I navigate.
Currently I am storing these values in a separate class (with row and column no.)but now I am searching some way so that I can store those values in my view only.
Is it possible in BC4J view ? I heard that something like this is provided in BC4J view but not able to find out..
thanx once again
I welcome some other suggestions on it.. -
Maximum length of query string for functions return a SELECT
Hi all,
I have a report that gets it's SELECT statement from a function, instead of being coded into the region. All was well but I suspect now I'm blowing some kind of limit as I'm getting an error :
ORA-06502: PL/SQL: numeric or value error
Error ERR-1101 Unable to process function body returning query.
However if I run the procedure out of ApEx and grab the SELECT statement then it works fine. The length of the query is 8636 bytes (yup, it's a beauty!).
Does anyone know if there is a hard limit to the size of the string that can be returned?
I'm using ApEx 3.1.
Thanks,
Steve HI do have a similar painfull scenario - Although my query length is very less i.e 618 bytes only.
I have defined a stored function, which returns an SQL query string, this return SQL string executes fantastic but when I tried to to call this function from a APEX report it gives error. the details are as follows. Please help.......
The function code:
CREATE OR REPLACE function PROD."TEST_C_QRY"
return VARCHAR2
is
msql VARCHAR2(32767);
Begin
msql:='Select null,statusname,AgeInd, ';
For m_stat in (select statusname from a02_status)
loop
msql:= msql || q'[decode(statusname,']';
msql:= msql || m_stat.statusname;
msql:= msql || q'[',count(id),0) ]';
msql:= msql || m_stat.statusname|| ',';
end loop;
msql:=rtrim(msql,',');
msql:= msql||' from ';
msql:= msql||'( ';
msql:= msql||'select a.id, round(sysdate-a.registeredon) TimeSpan,';
msql:= msql||'case ';
msql:= msql||q'[when round(sysdate-a.registeredon)<=7 then 'Week' ]';
msql:= msql||q'[when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' ]';
msql:= msql||q'[when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' ]';
msql:= msql||q'[else 'More...' end ageind,]';
msql:= msql||'a.status_id,b.statusname ';
msql:= msql||'from a02_task a,a02_status b ';
msql:= msql||'where b.id=a.status_id) ';
msql:= msql||'group by statusname,AgeInd;';
return msql;
end TEST_C_QRY;
The Output SQL comes from this is
SQL> Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,
'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round
(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then
'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
The result that comes when I execute the above resultant SQL is as follows.
N STATUSNAME AGEIND SCHEDULED EXECUTING COMPLETED
Completed More... 0 0 4
Completed Week 0 0 1
Scheduled Week 1 0 0
Completed Month 0 0 3
Executing More... 0 1 0
Executing Month 0 6 0
Scheduled More... 1 0 0
7 rows selected.
But the surprising error that comes from Oracle XE when I use the following code for stacked bar chart
Code:
begin
return TEST_D_QRY;
end;
Error thrown by XE report builder is as follows:
1 error has occurred
Failed to parse SQL query!
Select null,statusname,AgeInd, decode(statusname,'Scheduled',count(id),0) Scheduled,decode(statusname,'Executing',count(id),0) Executing,decode(statusname,'Completed',count(id),0) Completed from ( select a.id, round(sysdate-a.registeredon) TimeSpan, case when round(sysdate-a.registeredon)<=7 then 'Week' when round(sysdate-a.registeredon)>7 and round(sysdate-a.registeredon)<14 then 'Fortnight' when round(sysdate-a.registeredon)>14 and round(sysdate-a.registeredon)<30 then 'Month' else 'More...' end ageind, a.status_id,b.statusname from a02_task a,a02_status b where b.id=a.status_id) group by statusname,AgeInd;
Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
Regards,
Soumen -
Having trouble writing to a database although SQL query is correct
Hi there. I am trying to write an sql query to a database but I am failing to understand what is going wrong in terms of executing the query.
I have the following code.
static public int writeToStockTable (String suppIn, String nameIn, String typeIn, float quantIn, float priceIn, String descIn, String styleIn, String finishIn) { // Temporary variable to hold the SQL query String SQLString, SQLString2; ResultSet rs = null; // Build a string containing the SQL INSERT instruction to be used later SQLString = "INSERT INTO "+typeIn+" VALUES ('1', '" + suppIn + "', '" + nameIn + "', " + quantIn + ", " + priceIn + ", '"+descIn+"', '"+styleIn+"', '"+finishIn+"')"; SQLString2 = "SELECT Name FROM Suppliers WHERE Name = '" + suppIn + "'"; try { // The createStatement() method creates a Statement object. Object will be // attached to my reference variable (statement) defined at the top of class. statement = connectionToBellFiresDB.createStatement(); // The executeUpdate() statement can be used here to execute an // SQL INSERT instruction. rs = statement.executeQuery (SQLString2); if ((rs == null)) { System.out.println ("Trying to say no supplier"); return (-2); } else { System.out.println (SQLString); statement.executeUpdate (SQLString); } } catch (SQLException exception) { return (-1); // Return -1 if problem writing record to file } return (0); // Return with 0 if record successfully written }
Please ignore the attributes not used, it is very much a work in progress. The command that prints SQLString prints
INSERT INTO Fireplace VALUES ('1', 'a', 'a', 1.0, 1.0, 'a', 'a', 'a')
which is correct, but will return the error code -1 when asked to execute the query. The database jdbc:odbc driver has been initialised in the control panel and the program has no other problems accessing the database as far as i am aware.
Any help would be appreciated, i hate database connections :)Chrift wrote:
Im sorry i dont know what you mean by eating the exception, im quite a noob at programming to be honest!
How do i print it out and what is a stack trace?Do you know what an exception is? If not, then you should stay far away from JDBC/Database programming for the time being.
Read [the Exception Tutorial|http://java.sun.com/docs/books/tutorial/essential/exceptions/] first.
Then: an exception has quite a bit of useful information attached that tells you what went wrong.
In your case you catch the exception and ignore everything it could tell you by simply returning -1. Returning 0 and -1 to indicate success/failure is a very bad idea and should not be used in Java code, it's a C-style convention for C-era programming languages. In Java you use exceptions instead.
For starters you could simply add "exception.printStackTrace()" in your catch-block to get some more information out of the exception.
Maybe you are looking for
-
Date parameter in report whose source is SSAS cube shows all dates in DimDate?
My cube consists of a FactTable that has a foreign key to [DimDate], through column [DateKey]. My DateKey has dates from 20010101 to 20201231. My fact table only has data from today (20141017). In SSRS, I add the dimension Dim Date, Date Key as para
-
Status record 65 error in ale service
HI Experts, I have an issue when I tried to send a cost center idoc from one system to another. The company code for the record is 0093 in the sender system; however when the idoc gets created, in the idoc the value of the company code
-
Unable to save as "Reader Extended" in Acrobat 9.2
Hello, I have created a form in Acrobat 9.2. When I save the form and open it in Adobe Reader I can complete the form but I cannot save the completed form, only print. I need to save the save the form as "Reader Extended" but I cannot find the option
-
hello, i want to add our logo and address in the standard report of purchase order, please let me know how to do the same and what are steps to followed. please explain the entire details and steps and oblige. thanks suja
-
Displaying a JComboBox in JTable
I have a JComboBox in a JTable. The JComboBox contains JCheckBox's. To enable the user to select multiple checkbox items in the combobox, my class which extends JComboBox also implements ComboBoxEditor. In getItem I use showPopup inside a thread to e