Is there a way to set a parameter to equal a value selected on a form?
For example, I am trying to set my parameter [ComplianceDate] to equal my combobox selected value.
Something like:
PARAMETERS [ComplianceDate] DateTime;
[ComplianceDate] = Forms![myForm]![myComboxValue]
SELECT *
FROM myTable
Where myDate = [ComplianceDate]
Revise the report's RecordSource query ...
PARAMETERS [ComplianceDate] DateTime;
SELECT *
FROM myTable
Where myDate = [ComplianceDate]
Use DoCmd.SetParameter to supply a value for the parameter and then open your report ...
DoCmd.SetParameter "ComplianceDate", Forms![myForm]![myComboxValue]
DoCmd.OpenReport reportName
Related
I have a SP like this:
ALTER PROCEDURE [dbo].[ReportGateWay]
(
#ISO bigint= 0,
#Gateway bigint= 0
)
AS
BEGIN
DECLARE #SQL nvarchar(max)
SET #SQL= 'SELECT * FROM
(
SELECT DISTINCT I.DBAName [ISOName], BG.GatewayName
FROM Iso I
LEFT OUTER JOIN BusinessGateway BG
ON I.GatewayName = BG.MerchantBusinessGatewayId AND I.IsActive = 1 and BG.IsActive = 1
WHERE ('+CAST(#ISO AS varchar(10))+' = 0 OR I.IsoId = '+ CAST(#ISO AS varchar(10)) +')
AND ('+CAST(#Gateway AS varchar(10))+' = 0 OR BG.MerchantBusinessGatewayId = '+ CAST(#Gateway AS varchar(10)) +')
) AS tb1
PIVOT
(
Count(GatewayName) for GatewayName in ('+ SUBSTRING((SELECT ',[' + BG.GatewayName + ']' FROM BusinessGateway BG
WHERE #Gateway = 0 OR BG.MerchantBusinessGatewayId = #Gateway
FOR XML PATH('')), 2, 200000 ) + ')
) AS pvt
ORDER BY pvt.ISOName'
EXECUTE (#SQL)
END
I need to invoke this in SSRS. The problem is that when on creating dataset for this, I get an error which read:
You must have atleast one field for your dataset
What can be done in this case?
You have this error message because SSRS cannot infer your schema from the query.
You could declare manually your fields in DataSet Properties => Fields:
Field Name, Field Source
ISOName, ISOName
Gateway1, Gateway1
Gateway2, Gateway2
EDIT
If you really want to have dynamic columns and can't define static column names, you could try a trick like this.
The idea is to create a function returning an Arraylist containing Column headers and values.
Why are you not executing the Procedure by creating a dataset of query type "Stored Procedure"?
By doing this you will be able to see the fields getting returned from the SP in your dataset.
You can also pass the parameter values to the SP by creating the report parameters.
Edit:
How to pass parameter to SP in SSRS:
Say you have sp as below:
create procedure [dbo].[TestProcpk] #value varchar(20)
as
select * from testProc where value = #value
You have to create parameters with same name as above i.e. #value.
I have below data in testProc:
ID|Value
1|xxx
2|yyy
3|zzz
If I run the report with parameter value of xxx, I will get 1|xxx only.
Also, You don't have to specify anything after selecting the SP from drop down.
How you are not able to pass param value to SP?
I'm using SSRS to build report. Format of my query is as follows
declare #Date smalldatetime
select #Date = '20140421'
exec API_someAPI
#DateStart = #Date
,#DateEnd = #Date
select ...
where t1.Column < #Date
the problem is when enter this code in query editor, to form all necessary parameters, it asks for #DateStart and #DateEnd, but not for #Date. Shortly, it generates two parameteres, but I need #Date parameter, and it does not gebnerate it. I've tried to create it manually, and changed text as follows
..
select #Date = #Date
..
and created a new parameter, but query didn't work that way. How can I solve this problem?
I have a column in table which has following values. Names are separed by comma..
ProjID Names
1 Adam , Babita Tripathy, Alex, Mihir , Farhad
2 SaravanaKumar, Shruthi, Arthi, Suneeth
I am passing input value to stored procedure to fetch values. The input value is multiple names. If input is (Arthi,SaravanaKumar) i need to get both the rows as result because ProjID 1 and 2 has one of the input names. How can i achive it. Please help..
Search Condition.
IF #Names<>''
SET #condition = #condition+' ProdType.NamesLIKE'''+'%'+RTRIM(#Names)+'%'' AND'
You can use a function to split he input string
IF EXISTS(SELECT * FROM sysobjects WHERE ID = OBJECT_ID('UF_CSVToTable'))
DROP FUNCTION UF_CSVToTable
GO
CREATE FUNCTION UF_CSVToTable
(
#psCSString VARCHAR(8000)
)
RETURNS #otTemp TABLE(sID VARCHAR(MAX))
AS
BEGIN
DECLARE #sTemp VARCHAR(10)
DECLARE #tTemp VARCHAR(10)
WHILE LEN(#psCSString) > 0
BEGIN
SET #sTemp = LEFT(#psCSString, ISNULL(NULLIF(CHARINDEX(',', #psCSString) - 1, -1),
LEN(#psCSString)))
SET #psCSString = SUBSTRING(#psCSString,ISNULL(NULLIF(CHARINDEX(',', #psCSString), 0),
LEN(#psCSString)) + 1, LEN(#psCSString))
INSERT INTO #otTemp(sID) VALUES (#sTemp)
END
RETURN
END
Go
It can be called like this.
select * from UF_CSVToTable('1,2,3,4,5,6,7,15,55,59,86')
SQL FIDDLE DEMO
I'm having a hard time in assigning values that came from my database,
Value to be retrieved :
AppointmentTime
Value = 11:00:00
Data Type = time(0)
I use VS 2010 to assign that value from SQL Server 2008 with a DateTimePicker..
DateTimePicker1
Format = HH:mm
MinDate = 1/1/1770
DateTimePicker1.Value = Appointment Time
It gives me an error of 'Value of 1/1/0001 11:00:00AM is not valid for Value. Value should be between MinDate and MaxDate..
I wonder why SQL Server 2008 gives a value of Date, in my Time(0) Column?
I try this query
declare #x time(0);
set #x = getdate();
print cast(#x as datetime);
It will be give you the time with the date 01/01/1900.
So, try to cast Appointment Time to DateTime before set the DateTimePicker1 value.
Is it equivalent ORACLE cursor parameter feature in MySQL ?
For example :-
CURSOR cursorname(paramter_name datatype) IS SELECT * FROM TABLE_NAME;
You can try the following:
CURSOR select_curs IS SELECT * FROM tbl WHERE id = #id;
set #id = 1;
OPEN ..
FETCH ..
CLOSE ..
like this:
The procedure uses the var_id_res parameter to specify a particular reservation:
This procedure parameter is used to control a cursor to select only items that correspond
CREATE PROCEDURE `UpdatePriceAndVatAndDiscountForReservationItems`(
IN var_id_res INTEGER
)
...to the reservation passed by the parameter:
-- the line reserve curosr
DECLARE cur_res CURSOR FOR
SELECT id_line
, id_prod
, disc_bool
, no_days
FROM line_reserve
WHERE id_res = var_id_res;