How to set mysql user variable when report loading Birt - mysql

Im using birt reporting tool since from year. its cool product very good.
Today i got a problem. that i want to set mysql user varible when report loading as a example SET #user="USR009";
I tried several ways to do this i couldnot get the answer could some one help me on this issue very thank full
im stuck on this problem
regards
roshan

You can set the value in the query using a report parameter, and initialize it in the script.
Add a report parameter (PARAMETER_1)
Add "SET #user = QUERY_PARAMETER;" before your select statement in your data set.
While the data set is selected, select the script tab and find the "beforeOpen" drop-down. In here, add a line: this.queryText = this.queryText.replace("QUERY_PARAMETER", params["PARAMETER_1"].value);
The script will replace all instances of QUERY_PARAMETER with the text. You might still need quotes around it in the set statement (i.e SET #user = "QUERY_PARAMETER";).

Problem Was resolved create a SP
delimiter //
Create PROCEDURE abcd(param INT)
BEGIN
SET #USER=param;
SELECT #USER;
END//
And in your query call the SP with varible;
works like charm

Related

SSIS Execute SQL Task error no rows returned

I am a bit new to SSIS and given a task to send mail to particular stores based on Purchase Orders -> PONumber.
The steps should be as follows:
1)Take a XML file from a particular folder
2)Get the PONumber from that file
3)Write a query to fetch all the store email addresses for PONumbers
4)Send a mail to particular restaurant
Below screenshot is a package I had created. The only thing I am getting an issue is the Execute SQL Task , not sure what is the exact cause?
Could you please help on how can I debug this ? This was working fine before, but suddenly it started showing errors.
IMAGE1
IMAGE5
Execute SQL task is expecting results from the query, but is not getting any. Maybe you could use SQL Server profiler to catch exact SQL that is executed on SQL Server. Then you can use that SQL in query window to troubleshoot what it returns or why it is not not giving any results.
Edit.
With your current additional information interesting place is "parameter mapping" page, which you did not include. You should link SSIS variable to query parameter in there as Matt explained. SSIS does NOT link your variables in SSIS and query automatically even if they have the same names.
#dvlpr is correct your problem is you are getting NO results when Execute SQL Task 1 needs a single result.
The code you pasted is a little unclear as to which code is where but I will assume the first part is the code you use in SSIS Execute Task and the latter is an example in SSMS. If that is the case the problem is you are assigning the variable with a value of 0 in the script itself which I assume there is no PONUMBER that is 0:
Declare #POID as Varchar(50)
Set #POID = 0
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)
If you want to pass in the PONUMBER from your first dataflow task you need to load that to a variable and then use the variable in your Execute SQL task and made sure you setup parameter mapping correctly when doing so. here is one SO question on parameters that will help How to pass variable as a parameter in Execute SQL Task SSIS? And here is use of an expression task in a Data Flow task to set the variables value SSIS set result set from data flow to variable (note use the non-accepted answer that it was added later and was for 2012+ while the original was for 2008)
Next unless you are guaranteed only 1 result you will also need to add TOP 1 to your select statement because if you get more than 1 result you will get a different error again.
EDIT Per all of the comments:
So the configuration looks like you are using an ADO.NET connection which allows you to use named paramaters. There are restrictions if you don use that (https://msdn.microsoft.com/en-us/library/cc280502.aspx). The parameter mapping looks correct, and the result set should be fine. As far as your Error I don't know because you haven't posted the exact error so I cannot know what is the problem. If you use ADO.Net with your current Execute SQL Task configuration in the images you do have a couple of problems. 1 you are trying to declare the variable that you want to pass as a parameter that doesn't work, you need to remove that DECLARE statement. I suspect all you really need to do is modify your SQL Input to be:
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER, FAN_Suppliers.SupplierName,
FAN_Company_Details.CompanyName, FAN_Company_Details.[PrimaryEmail],
BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER INNER JOIN
FAN_PO_Details ON BizTalk_POA_HEADER.PONUMBER =
CONCAT('PO',FAN_PO_Details.PoNumber) INNER JOIN
FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID
INNER JOIN FAN_SupplierDetails ON FAN_PO.SupplierDetailsID =
FAN_SupplierDetails.SuppliersDetailsID INNER JOIN
FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID
INNER JOIN FAN_Company_Details ON FAN_PO.CompanyID =
FAN_Company_Details.CompanyDetailsID
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)
Just get rid of the declare #POID and SET = 0 for a couple of reasons 1 because it is redundant when you have setup parameter mapping, 2 SSIS doesn't like it and will throw an error, 3 because you are setting a value of 0 to it which means it would always be 0.....

Multiple condition in if....else inside stored procedure

IF region='Mumbai' OR region='Chennai' OR region='Bangalore' OR region='Pune' region='Coimbatore' OR region='Ahmedabad' THEN
SET region='South-west';
ELSE
SET region='North+East';
END IF;
I am trying to create a sp i have error in the above the Condition. rest of the Stored procedure is working fine when i remove the above if condition.
i am getting the error for multiple or condition in if statement.
please help.
You are missing an OR. Try:
IF region='Mumbai' OR region='Chennai' OR region='Bangalore' OR region='Pune' OR region='Coimbatore' OR region='Ahmedabad' THEN
Also, I think an IN would work here as well (I'm not 100% sure since I don't use MySQL regularly):
IF region IN ('Mumbai','Chennai','Bangalore','Pune','Coimbatore','Ahmedabad') THEN
That would be much more readable, if MySQL is happy with it.

ASP.NET Update Command and SQL Logic

I am attempting to use the update command on an ASP.NET website and my logic of SQL follows:
UPDATE (SELECT `Event Name`,`Date`,`Time`,`Location`,`Goal`,`ID` FROM Calendar)
but, MySQL returns an error:
#1248 - Every derived table must have its own alias
Any ideas to fix this would be appreciated. Also, I have seen this alternative to plain SQL commands: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.updatecommand.aspx
All solutions would be helpful in structuring this ASP site (C#). Please keep in mind I am new to this technology.
The update statement looks a bit weird. Shouldn't it something like this:
UPDATE Calendar
SET [Event Name] = #Event, Date = #date, Time = #time,
Location = #location, Goal = #goal
WHERE ID = #id
Watch the spaces in column names, you should surround them with square braces, i.e. [Event name].

SQL Update returning zero rows

UPDATE starfsfolk
SET starfsfolk.stada=2
WHERE starfsfolk.deild LIKE '%Hugbúnaðardeild%';
UPDATE starfsfolk
SET starfsfolk.stada=3
WHERE starfsfolk.deild LIKE '%Markaðsdeild%'
is prescisely the code i'm using.
i've tried various different versions of it(like = "Markaðsdeild" or LIKE "Markaðsdeild")
most of which work if i'm using select, but i needed to use update and its not working for some reason.
This WHERE command works on select but
it returns zero rows if i'm using the update command. What am i doing wrong?
Edit:
Just to clarify, stada is set to 1 in all cases before and after the update command. it hasn't changed from 1 to 2 and 3 like i wanted it to.
Edit2: heres a screenshot of the database, i could also give you the create commands.
Edit3: Stada is bit, not int, i found out, not sure what that changes tho.
Solution: Solved myself, since bit is just 1 and 0, the error was in the creation of the table so i remade it with stada as int and now the code is working.
If the value of stada is not changed by the query then zero rows will be returned because nothing was updated.
The character sets of the server and of the client are different.
http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

Parameters in SQL Server 2008

I have a stored procedure that pulls data for a report. I'm having a problem with the parameters. I have a couple temp tables and some joins that work so I have omitted them below. The problem is this line:
WHERE
SeminarDivision = #SeminarDivision AND SeminarType = #SeminarType
When I put this where clause in to use my seminar parameters the stored proc returns nothing But I need to generate a report based on those two parameters. So where do the parameters go? Can anyone help?
#StartDate DateTime,
#EndDate DateTime,
#SeminarDivision VARCHAR(50),
#SeminarType VARCHAR(50)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
... OMITTED
SELECT
WL.PID,
CONVERT(varchar(20), upper(substring(FirstName,1,1))+
LOWER(substring(FirstName,2,19))) AS FirstName,
CONVERT(varchar(20), upper(substring(LastName,1,1))+
LOWER(substring(LastName,2,19))) AS LastName,
S.SeminarDivision,
S.SeminarType,
S.StartDate,
S.SeminarLocation
FROM
#tblWaitList WL
INNER JOIN #tblSeminar S ON WL.SeminarGuid=S.SeminarGuid
WHERE
SeminarDivision = #SeminarDivision AND SeminarType = #SeminarType
ORDER BY
LastName,FirstName,StartDate
First and foremost there is nothing wrong with your code, when asking where do these parameters go, they go exactly where you put them. The question is - is the data coming in for SeminarDivision and SeminarType the right type of data? For instance just as a test,
copy the code into a new sql code query inside the editor. Run the command without the where, if you get values great. Now change the where to
WHERE
SeminarDivision = "Possible_Value"
Where Possible_Value should be a possible value...If it returns rows, good...now add the second condition also hardcoding a value:
WHERE SeminarDivision = "Possble_Value" AND SeminarType="Possible_Value_2"
Getting any data? Is it possible you want OR rather then AND ?
There's nothing wrong with the 'location' of your params.
If you're getting no data back, it's either because you've not populated #tblWaiList or #tblSeminar or because the records simply don't match your WHERE clause.
Check your params have the value you think they do by executing print #SeminarDivision etc.
SELECT * FROM #tblSeminar may give you a clue too.
You are not setting parameters correctly for the call.
Try this in SSMS, change values accordingly
EXEC Proc '20110101', '20111101', 'PossibleDivision', 'PossibleType'
If this fails, then show us "OMITTED" code
if this works, show us how you are calling this from the client code