Dynamic Parameter Values For Subscription

Jan 26, 2008

I have been trying to add in date functions for parameters in a report subscription and they are not accepted. I have a report with 2 parameters, @start and @end. I have default parameters set wtihin the report of Now - month for @start and Now for @end. Can my users create a subscriotion using something like "=DateAdd("D", -1, Now)" for the parameters rather than the default?

View 8 Replies


ADVERTISEMENT

The Subscription Contains Parameter Values That Are Not Valid.

Feb 28, 2008



Hi,

We have a report server which has lots of reports. this particular report has 375 subscriptions and 80% of them are failing with the error "The subscription contains parameter values that are not valid." since last week nothing new was done on the server. when I open the properties of one of the subscriptions, one of the parameter value shows as a number where as it should be the name of a state.

Not sure what to do to get the subscriptions back.

any Ideas/help greatly appreaciated.

Thanks,
Phani

View 5 Replies View Related

Using Parameter Values In Subscription Fields?

Sep 6, 2007

Anyone know if it is possible to reference the parameter values stored for a given subscription, in the subscription fields (subject/comment)?

So instead of just @ReportName at @ExecutionTime it could be @ReportName at @ExecutionTime (@ReportParameter1)

I know I can do this in data driven subscriptions, but was wondering if it was possible without.

Thanks,

View 1 Replies View Related

The Subscription Contains Parameter Values That Are Not Valid

Mar 10, 2008

Hello,
I have something like 100 regular subscriptions.
It sometimes happen that one of the subscriptions suddenly stop to work with error "The subscription contains parameter values that are not valid". Example, one report has a dozen subscriptions, one of them stop to work. I look into the subscription and see that either one of the parameters is no longer set to a value or see nothing special besides the warning at the top of the subscription page. Parameters are all set to either default or some value(s). I reset one of the parameters, validate, or simply validate with no change and it works again.
Next time, in one or three weeks another subscription will fail, I will reset it.
Sometimes there are no errors, sometimes just 1 error and sometimes multiple errors accross reports or sometimes one report will suddenly have a few errors.
Right now, I use a weekly report to warn me after the fact of what were last week errors if any (no data, parameters unvalid, etc).
It looks like it happen with strings parameters based on datasets like "Sales offices" by example, where value and label are the same. Note that sales offices are by nature very stable, we do not change the spelling nor add remove entries. The list being a dataset gets rebuild, just to make sure we do not miss any eventual new sales office but if there is a new sales office, no one had a chance to select it as parameter value before it is in the dataset.
I am really not sure what is going on, were parameters values changed in the metadata? I do not think so.
Anyways, Is there a way to get an early warning instead of an after the fact error warning?
Is there anything else I coud try to "Refresh" or "remap" parameters values to avoid these errors?
When the subscription was created by a business analyst, If the parameters becomes blank, I have a hard time figuring out what it was when it was still valid. Is there any way to have a list of parameters values and have these values automatically "re-selected" by report server when the value gets lost?
This is not a big problem however it is annoying and people will have a bad perception of the system quality. "I created a subscription for Sacramento and never got my report", some people will also introduce garbage because they will create a new subscription instead of fixing the broken one, then they may eventually get twice the same report.
Any thought, does anyone had the same problem?

View 2 Replies View Related

SSRS -- Data Driven Subscription And Pivoting For Dynamic Parameter Mapping

Feb 12, 2007

Hi,

For the Data Driven Subscription in SSRS we are using the following stored procedure

In Step 3 - Create a data-driven subscription



create procedure spRSGetReportSettings

(

@ReportID as integer

) as

begin

set nocount on

declare @t as table(y int not null primary key)

declare

@cols as nvarchar(max),

@y as int,

@sql as nvarchar(max)

set @cols=stuff(

(select N',' + quotename(y) as [text()]

from (select ParameterName as y from Reportsettings where reportid=1) as Y

order by y

For XML Path('')),1,1,N'');

set @sql=N'select * from

(select reportid,parametername, parametervalue from ReportSettings where reportid= ' + Cast(@ReportID as varchar(5)) +' ) as D

pivot(min(parametervalue) for parametername in(' + @cols +N')) as p'

exec sp_executesql @sql

end



Basically the idea is to maintain a single report parameter setting table for multiple reports.

Structure of the table is as given below

ReportID, ParameterName, ParameterValue.

Using Pivot we can generate the ParameterName/ParameterValue combinations for each report. This stored procedure is working fine in query editors(Management Studio)

But, in SSRS it is giving any results.

In Step 4 - Create a data-driven subscription,

Get the value from the database drop down, I am not getting any database columns.

Please help.

Kumar

View 3 Replies View Related

Using Of Substring With Dynamic Values For Length Parameter

Feb 12, 2003

Hi everybody,

I want to use substring with dynamic
values for length parameter
but result is different compare to
static parameter.

declare
@x smallint,
@y smallint,
@string varchar(250)


set @x = 0
set @string = '17898880219800alex3.5'

select @y = charindex('',@string,@x)
-- result varchar(5)
select substring(@string,@x,5)

select @y
-- result varchar(250) !!!!!!

select substring(@string,@x,@y)

Any Idea why ?

View 3 Replies View Related

Analysis :: Dynamic Default Values For Parameter

Nov 11, 2015

I am trying to write a query for the default values for month, and I am stuck in bringing out only the parameter values, the query I have , brings back the month on row and value on column, and I am trying to get the value out. and will ssrs accept it as a valid expression for a default value

WITH 
MEMBER
[MEASURES].[PARAMETERVALUE]
AS
[Account].[Month Short Name].CURRENTMEMBER.UNIQUENAME

[Code] .....

I tried using the exp

=Parameters!MONTH.Value(0)

so as to return the first parameter in the parameter dataset , but i have the error the expression that ref the parameter MONTH does not exists in the parameter collection.

View 2 Replies View Related

Can You Create A Subscription With A Dynamic Date

May 15, 2007

Hello,



I am curious if you can create a subscription for a report that resides on reports manager with a dynamic date? We have a couple of reports on reports manager that require a date value and I tried to use getdate() for the value but it will not except it. Is there a way to have a subscription do something like this so the end user doesn't have to change the date parameter each time? Thanks in advance.



John

View 4 Replies View Related

How To Get Mobile Subscription To Sync With Dynamic Snapshot

Feb 8, 2007

Hello Everyone,

I have a publication on a Sql 2000 (SP4) server. This publication has dynamic filtering enabled. What I want to do is create an interface which will generate a new dynamic snapshot based on filtering input from users. So far I can create the dynamic snapshot easy enough and I can see the filtered results on a Sql 2000 subscriber. However, there seems to be no way to configure a mobile database to point to the dynamic snapshot. This is easy to configure in a Sql 2000 subscription - the options are right there are on the properties page. Yet, it seems like the mobile database only points to the required unfiltered snapshot through the IIS proxy.

Is there any way to force the mobile database to use the dynamic snapshot instead?

Thanks,

Mike



View 6 Replies View Related

Subscription Parameter Not A Valid Value

Oct 4, 2007

Hi,

I'm trying to set up a data-driven subscription and having problems with parameters. On the Report Parameter Values screen of the Create Data-Driven Subscription function I have set a parameter TimesheetPeriodEnd to "Specify a static value" and checked the NULL box. In the report the parameter is type string and allows nulls. When I try to run the subscription the reports are not sent and the error log contains the following message:

ReportingServicesService!library!f!10/05/2007-09:31:08:: Status: Failure sending mail: Default value or value provided for the report parameter 'TimesheetPeriodEnd' is not a valid value.
ReportingServicesService!notification!f!10/05/2007-09:31:08:: Notification 0ae544df-4b1b-4a46-b7ab-cdefdca201be completed. Success: False, Status: Failure sending mail: Default value or value provided for the report parameter 'TimesheetPeriodEnd' is not a valid value., DeliveryExtension: Report Server Email, Report: Timesheet, Attempt 0

I am also setting other parameters for this subscription in the same way and not getting errors.

Any ideas? Previously I have had problems passing null values to parameters from the subscription query "Get value from database" from SELECT NULL AS ParameterName (this function just doesn't seem to work in SSRS). But I'm surprised I can't even seem to get this working with the default settings.

Regards,

Greg

View 5 Replies View Related

Pass Parameter For Subscription

Oct 17, 2007

Hi
I want to create subscription for the report.
I have 1 date parameter. and i want the value of the date parameter as today s date.
How can i set value of the parameter as today's date.

I have tried using

getdate
today
now
getutcdate

didnt work.

any other option.

I need to create subscription either from report manager or from management studio

View 1 Replies View Related

Sync_type Parameter In Subscription

Jun 12, 2006

Hi,



I tried to change the subscription property "sync_type" whith a system procedure but I was not able to do it, because sp_changesubscription does not support this property.



Is there any chance to change this property by procedure?



So I decided to drop the subscription and define it new with sp_addsubscription. I chose to set this to "replication support only" as the value "none" is depricated based on the online help. Unfortunately using this value results in an error message "only none or automatic is allowed".



How can I set this value now to "replication support only"?



I need to set the value to "replication support only" as this value leads into the generation of the stored procedures used for insert, update and deletes.



The purpose behind this, to restart a transactional push replication, doing all the initialization stuff by myself and not with reinitialize subscirption. I would like to decide, if I do the initialisation.

Regards

Nobsay

View 5 Replies View Related

How To Make A Subscription Use The Default Value For A Parameter

Sep 18, 2007

Hi everyone,

I need to use the CreateSubscription method and have this new subscription use a default value for certain parameter. How can I do this?

View 7 Replies View Related

Parameter Driven Subscription - Error

Apr 22, 2008

I have set up a parameter driven subscription and am having strange results. This subscription is being set up as Web-archive, including the report and link.

At first when setting up the report, I didn't have a default value set in the report, but would choose it in the subscription and would see an error saying the parameter value provided is not valid. After seeing the error I would edit the subscription and see the parameter value was blank. This would happen if the subscription was set to start after at least a few hours. This didn't matter if I chose the subscription schedule or using a shared schedule.

When I set up a subscription the same way, but then had it delivered within the next few minutes, the report would work fine, using the given parameter.

Since one of reports is being sent to a manager, I put in a default parameter value and set up a few subscriptions. I was hoping at least if the subscription "didn't remember" the parameter value, the default would be used and delivered. I was right, the report was delivered using only the default... but will only be delivered using the default.

There have been quite a few people posting similar questions, but none of them are answered.

Any help is greatly appreciated.

Thanks in advance,
Eric

Ps - here is some of the log file relating to one of the failed subscriptions:
From: ReportServerService*.log
ReportingServicesService!library!10!4/19/2008-02:00:05:: i INFO: Schedule 93453b16-89d3-48d1-a470-d7a09fc163b6 executed at 4/19/2008 2:00:05 AM.
ReportingServicesService!library!10!4/19/2008-02:00:05:: i INFO: Schedule 93453b16-89d3-48d1-a470-d7a09fc163b6 execution completed at 4/19/2008 2:00:05 AM.
ReportingServicesService!dbpolling!10!4/19/2008-02:00:05:: i INFO: EventPolling finished processing item e40d5803-bb69-4d20-bd55-797074969348
ReportingServicesService!dbpolling!12!4/19/2008-02:00:05:: i INFO: EventPolling processing 1 more items. 1 Total items in internal queue.
ReportingServicesService!dbpolling!f!4/19/2008-02:00:05:: i INFO: EventPolling processing item fe04012c-6376-4599-b980-6aa1c77036fd
ReportingServicesService!library!f!4/19/2008-02:00:05:: i INFO: Schedule 93453b16-89d3-48d1-a470-d7a09fc163b6 executed at 4/19/2008 2:00:05 AM.
ReportingServicesService!schedule!f!4/19/2008-02:00:05:: Creating Time based subscription notification for subscription: f2551ca1-f6b8-4394-8036-7fa8a9be1070
ReportingServicesService!library!f!4/19/2008-02:00:05:: i INFO: Schedule 93453b16-89d3-48d1-a470-d7a09fc163b6 execution completed at 4/19/2008 2:00:05 AM.
ReportingServicesService!dbpolling!f!4/19/2008-02:00:05:: i INFO: EventPolling finished processing item fe04012c-6376-4599-b980-6aa1c77036fd
ReportingServicesService!dbpolling!12!4/19/2008-02:00:05:: i INFO: NotificationPolling processing 1 more items. 1 Total items in internal queue.
ReportingServicesService!dbpolling!f!4/19/2008-02:00:05:: i INFO: NotificationPolling processing item d1e8f484-659e-48a1-a5da-747108ce63af
ReportingServicesService!library!f!04/19/2008-02:00:06:: i INFO: Initializing EnableIntegratedSecurity to 'True' as specified in Server system properties.
ReportingServicesService!library!f!04/19/2008-02:00:06:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.InvalidReportParameterException: Default value or value provided for the report parameter 'day' is not a valid value., ;
Info: Microsoft.ReportingServices.Diagnostics.Utilities.InvalidReportParameterException: Default value or value provided for the report parameter 'day' is not a valid value.
ReportingServicesService!notification!f!04/19/2008-02:00:06:: Notification d1e8f484-659e-48a1-a5da-747108ce63af completed. Success: False, Status: , DeliveryExtension: Report Server Email, Report: Daily RTS time, Attempt 0
ReportingServicesService!dbpolling!f!04/19/2008-02:00:06:: i INFO: NotificationPolling finished processing item d1e8f484-659e-48a1-a5da-747108ce63af

View 14 Replies View Related

How To Use Default Parameter Values With A Date Parameter From A Cube/Reducing Parameters

Oct 15, 2007



Hi,

I have parameters in my report. The user can choose the year, month and date (3 parameters).
Now I want to set default vaules for the parameters , so that the user sees the report for example for the current day without selecting the parameters. I tried to set the type of the parameters to DateTime and the default value for example for the year to "=Today().Year" . But when I execute the report an error occures . Something like : no validValue for this parameter.

My Attributes for the year month and date are from an Analyis Services Cube from a Server Time dimension .
Does somebody know how to make it possible to set default values for this parameters?



Other question :

Does somebody know how I can reduce the values for a parameter. For Example I have a parameter "year" from a server time dimension from a cube. The values which are available are "Year 2004", "Year 2005", "Year 2006", "Year 2007".
But I want that the user only can choose "Year 2006" or "Year 2007" ant not every Year or "All".
Or Other Example: The User should only choose a Date that is int the past or Today but not a Date in the future.


Thanks !

JF

View 7 Replies View Related

Reporting Services :: Data Driven Subscription With Dynamic Email Attachment File Name

Feb 11, 2010

I have report which accepts a card number and fromdate and todate as parameters to the report. This report needs to be sent on a quarterly basis to each of the customer mail id to which their card number is linked. I am getting all this information from a database and sending as an attachment to the customer. Now I would need making these filename's which are attached to be dynamic based on the input parameters.

In datadriven subscriptions, the option of include report has only true or false values and another option was to take from a database. I tried putting the dynamic file name in the database and getting the value from the database but no success, the subscription itself is failing here. I guess I am doing something wrong here by binding the report name from the value which I am getting from DB to the actual report name.

If report name = Mytransactions, and the parameters passed are Card = 123,fromdate = 1/1/2010,todate = 31/3/2010.

Now in the attachment the file name should be something like "Mytransactions_123_January1st2010_March31st2010".
How to make the filename dynamic.

View 9 Replies View Related

Is It Possible To Dynamically Populate A Parameter List With Values Based On Another Parameter Value?

Aug 11, 2005

Is it possible to fill a parameter list with values based on another parameter value?
Here's what I have so far (which hasn't worked)...
I'd like to generate a report listing information for a student.  The report viewer would first select a school from the first drop-down menu, and then the second drop-down menu would populate with the list of students at that school.
I have a dataset that calls a sp which returns a list of schools (SchoolID and SchoolName fields from the database table).
I have another dataset that calls a sp (with SchoolID as the parameter) which returns a list of students for that school.
Both datasets return the appropriate data when tested individually, but when I set up the Report Parameters and build the report, these errors come up...
The value expression for the query parameter '@SchoolID' refers to a non-existing report parameter 'SchoolID'.
The report parameter 'Student' has a DefaultValue or a ValidValue that depends on the report parameter "SchoolID".  Forward dependencies are not valid.
...Is it possible for the reoprt to generate a list of available parameter values based on the value selected for another parameter?
Any help you can give me would be great!!  Thank you

View 5 Replies View Related

How Do I Enter In A Default Values For A Report Parameter That Accepts Multi Values

Apr 11, 2008



I have my stored procedure set to
Territory_code IN (@Territory)

, now , how do i enter in more then one value. When i select the multi value check box, it gives me more spaces. But then doesnt recognize the values when i put in more then one. am i doing something wrong?

The field is a Varchar 20

View 1 Replies View Related

Passing A Parameter To The Filename In A Report Subscription

Jan 18, 2007

I have defined a monthly substription for a series of reports. I would like to be able to pass a paremter used in generating the report to the file name define in the subscription.

I can do it if I used system names such as @datetime, but I want to be able to use a parameter unique to the report.

For example if the parameter for the report was CARS and I was quesrying Toyotas how can I get toyoats to show up in the file name?



Any suggestions?



View 1 Replies View Related

Delivering Multi Parameter Reprots By DD Subscription

Nov 15, 2007



HI All,

If I use more than one parameters in my reports, still would I be able to deliver those reports by Data Driven subscriptions?

Thanks

View 1 Replies View Related

Data-driven Subscription - Invalid Parameter?

Aug 23, 2007

Hi,

I've set up a data-driven subscription on a report but it's not sending and the error log says it's because:

Default value or value provided for the report parameter 'CSRFaxID' is not a valid value.

For the particular dataset record causing the error I'm passing the value Null to the report parameter. The report parameter CSRFaxID is set up with "Allow Null" and with a default value of Null. I can run the report in my browser with CSRFaxID set to null, but the scheduled subscription is not able to produce the report with the same parameter value. Does anyone have any idea what the problem is and how I can fix it?

Regards,

Greg McNamara

View 3 Replies View Related

Refreshing Parameter Values When A Higher Level Parameter Changes

Apr 30, 2007

Hi All.

I have a parameter (hidden) that gets its value using an expression base on another parameter.
When in the designer, the first time when the designer loads I can select the Parameter that controls the child parameter (expression lies in the default value section). The value changes.

When I change the parent parameter again, the value of the child parameter does not seem to change.

How can I make this parameter change automatically when the parent is changed ?

Any help will be appreciated.

Thanks,
Neil

View 3 Replies View Related

Data-driven Subscription: Put Parameter In The Filename Text

Feb 1, 2007

Hi all,



I've developed a data driven subscription report. I have a paramete (named "Data") that is a result of my query to the current date. It is working fine.

Now I would like to make one change: In the step4 of the creation of the data-driven report we have the option to give a name to the filename.The name that I gave was TestFile. In this option i'm also able to select the parameter instead of giving the name to the filename. Can I make something like TestFile_ & @Data? Wich would result in TestFile_01-02-2007? Or the only way is to make, in the query of the paramenter another field with this result?



Thanks in advance.

Marco.

View 1 Replies View Related

Passing Null Value Parameter To A Data-driven Subscription

Jun 13, 2007

I have a data-driven subscription (DDS) stored procedure that gets called when a subscription fires and returns parameters to a report. One of the parameter values I want to return is NULL, which also happens to be the default value of the corresponding report parameter.



When I set the report parameter to use the default value (NULL) when setting up the subscription in Report Manager, the subscription works fine. When I try to pass the NULL value from the DDS proc to the report, the subscription fails.



I do not know what the error logs say. I've rarely looked at them and what I have seen seems a bit cryptic. I've narrowed down through trial-and-error that passing the NULL value is the issue.



Has anyone else experienced this issue and do you have a resolution?



Thanks in advance for your assistance.

View 5 Replies View Related

Reporting Services :: SSRS Custom Start Date Subscription Parameter

Jun 3, 2015

Is it possible to have a custom start date parameter on a report? I would like to have a cumulative daily report for the week, Friday to Thursday. The final daily to run on the Friday, then the next week begins.  I have a enddate, which is today()-1 (for previous day); I need a start date to be variable.

In other words,

On a Monday, report pulls data from last Friday to Sunday;
On a Tuseday, report pulls data from last Friday to Monday,
On a Wednesday, report pulls data from Friday to Tuesday, etc,
until on Friday, the report pulls data from last Friday to Thursday.

View 4 Replies View Related

Adding Values To A Parameter That Can Take Multiple Values

Jun 6, 2007

If I have a Select statement like this in my C# code:
Select * From foods Where foodgroup In (@foodgroup)
And I want @foodgroup to have these values ... "meat", "dairy", fruit", what is the correct way to add the parameter?
I tried
meat, dairy, fruit
'meat', 'dairy', 'fruit'
but neither worked. Is this possible?

View 2 Replies View Related

Accessing Values Parameter Values From Another Report

Sep 20, 2007

Hi, How can I display a value of a report parameter from one report into a textbox on another report??

View 1 Replies View Related

DTS And Dynamic Connection Parameter

Feb 19, 2001

Hi,

i want to modify my DTS to don't have any maintenance to do on it if a Username or password change.

Each DTS will have an ActiveX script to read connections properties in a table that i created and will automatically set each connection in the DTS each time that the DTS Run. So, we will have only to update the table and the DTS will continue working fine.

To update the Connections properties i have no problem, the problem is how can i retrieve the data from my table to get the connection properties, without hardcoding a connection inside my ActiveX script? Because i don't want to have to change each ActiveX script in each DTS if the SQL Server paswword change.

Any idea will be appreciated

Thank

Martin

View 3 Replies View Related

MDX Dynamic Parameter Syntax

Nov 12, 2007



I have a SSRS report that I'm passing a dynamic parameter to another SSRS report.
The datasourse is a SSAS cube. Can anyone tell me the if following syntax is correct for receiveing report.
I'm having trouble creating the datasource for the second report. I'm new at SSRS so any help would be appreciated.

When I parse this code in management Studio I get the following
An MDX Statement was expected. An MDX expression was specified.


'= [SELECT NON EMPTY { [Measures]].[Qty Paid]], [Measures]].[US Cost]], [Measures]].[Qty Recd]] } ON COLUMNS, NON EMPTY

{ ([Division_Plant]].[Hierarchy]].[Plant Desc]].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS

FROM ( SELECT ( STRTOSET(([

+ " Parameters ! DivisionPlantDivisionDesc.Value + "[), CONSTRAINED) ) ON COLUMNS FROM [New GOLD]])

WHERE ( IIF( STRTOSET(([ " + Parameters ! DivisionPlantDivisionDesc.Value

+ " [), CONSTRAINED).Count = 1, STRTOSET(([ " + Parameters ! DivisionPlantDivisionDesc.Value + " [),

CONSTRAINED), [Division_Plant]].[Division Desc]].currentmember ) )

CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS'

View 6 Replies View Related

Retrieving Values From Dynamic SQL

Nov 1, 2004

Anyone know if it's possible to retrieve a parameterized value from dynamically executed SQL???

Code Example

Declare @table varchar(25)
Declare @somevalue varchar(3)
Set @table = 'sometable'
Set @somevalue = 'somevalue'

Declare @sqlBuild varchar(2000)

Set @sqlBuild = 'DECLARE @return varchar(3); ' +
' SELECT @return = COUNT(COLUMNAME) ' +
' FROM ' + @table +
' WHERE ' +
' value = ' + @somevalue
exec (@sqlBuild)


i want to be able to extract the value of @return for later use. this procdure works fine but I need to grab that value somehow.

Any suggestions?

View 3 Replies View Related

How To Pass Values In Dynamic Sql

Jan 23, 2007

hi, i have this sql statement:
@uname varchar(20)
select@sql = 'select user_name, password, role_code, expiry_date,effective_from,active from usermaster where userid='1' and username like'@uname%'

it is not worrking for me.i don't know how to pass values in dynamicsql,can any one answer for me please.

View 3 Replies View Related

Returning Values From A Dynamic SQL

Feb 19, 2006

I have an accounting database which contains data from various years.The frontend is a VB.Net program. At the year end, the program createsnew voucher and transaction tables and creates new stored procedures forthem.I just append the 'new year' at the end and create themie, Vouchers2001, Vouchers2002, Vouchers2003Similarly Transactions2001, Transactions2002.The data for all the years is in the same database.Also, I maintain a table called 'Books' which contains the Years forwhich data is present in the Database. The Structure of the Books tableisBookID BookYear1 20012 20023 20034 2004My Problem is that i need to know the current balance of any ledger forany year. The method to calculate the balance for any year is to startfrom the Minimum year in the Books table and continue upto the requiredyear. The SQL is as follows.DECLARE @iLedgerID AS INT --will be passed as parameterDECLARE @iYear as INT --will be passed as parameterDECLARE @CurrentBalance as MONEYSET @iLedgerID =1DECLARE @MinBook as INTEGERDECLARE @String nVarchar(4000)SELECT @MinBook = Min(BookYear)FROM BooksWHILE @MinBook <= @iYearBEGINSET @String = ' DECLARE @TT Money ' + char(13) +' SELECT @TT = ISNULL( SUM( ISNULL(Debit,0) - ISNULL(Credit,0) ),0 )'+ ' FROM transactions' + CAST(@MinBook AS CHAR(4)) + ' LEFT OUTER JOINdbo.Vouchers' + CAST(@MinBook AS CHAR(4)) + ' ON dbo.Transactions' +CAST(@MinBook AS CHAR(4)) + '.VoucherID' + ' = dbo.Vouchers' +CAST(@MinBook AS CHAR(4)) + '.VoucherID ' +'WHERE (LedgerID = @iLedgerID)'EXEC sp_executesql @String, N'@iLedgerID Int', @iLedgerID */SET @MinBook = @MinBook + 1ENDNow this is just a sample code. It may have a few glitches. My questionisa) Do I have to create a dynamic sql if the name of the database is notknown ahead of time. If No thenb) I need to add the balance of each year to the grand total. How do ireturn a value from a dynamic sql.TIA*** Sent via Developersdex http://www.developersdex.com ***

View 6 Replies View Related

Dynamic SQL && Parameter Inside A SP Not Working

Nov 5, 2006

When I run the query below on my DB, it gives the following error:
Server: Msg 8114, Level 16, State 5, Procedure partstlist ...Error converting data type varchar to float.
Only after I replace the      " + @d + " section with a float numnber such as 39020.5 does it work fineIt's reported that my temporary table named #tbl doesn't exist within the scope of the environment that the EXEC(UTE) command operates.Someone said that I couldn't combine dynamic SQL and temporary tables or table variables...and that I would have to use a global temp table "##tbl" or a permanent table.
So here I have appearantly a "DYNAMiC SQL & TEMPORARY TABLE" problem. That's sure.
But I don't have much knowledge and experience with SQL tables and have difficulty forming a global temp table "##tbl" or a permanent table.and I have to employ the datetime variable dynamically @d inside the Dynamic SQL string.
So what kind of a code should I use here to properly combine Dynamic SQL string with my dynamic datetime variable? I'd be grateful if you could post your code suggestions so that I can try them on my DB ..
alter PROCEDURE partslist@no INT,@dt DATETiMEASDECLARE @s VARCHAR(5000)DECLARE @d floatSET @d = CONVERT (float, @dt2)create TABLE #tbl(pageindex int IDENTITY(1,1) PRIMARY KEY , prt_name varchar(50), prt_country varchar(50) , prt_date smalldatetime, partID int , prt_cat varchar(50),prt_product_type nvarchar(10), producer_company nvarchar(50), producer_city nvarchar(50), prt_released DATETIME, dvalue float, datevalue varchar(26) )BEGiNSET ANSI_WARNINGS OFFSET ROWCOUNT @noSELECT @s = 'INSERT INTO #tbl SELECT prt_name, Countries.Val AS ''prt_country'' , prt_date, partID , partsCategories.Val AS ''prt_cat'' , partsProductTypes.Val AS ''prt_product_type'' , producers.producer_company AS ''producer_company'' , producers.producer_city AS ''producer_city'' ,  prt_released , CONVERT (float, prt_released) , CONVERT (varchar(26) , prt_released, 109) FROM producer_parts  JOIN partsProductTypes ON (producer_parts.prt_product_type = partsProductTypes.ID) JOIN partsCategories ON (producer_parts.prt_cat = partsCategories.ID)JOIN Countries ON (producer_parts.prt_country = Countries.ID) JOIN producers ON (producer_parts.producerID = producers.producerID) WHERE prt_visible = 1  AND CONVERT (float, prt_released) > ' + @d + ' AND CONVERT (float, prt_released) < 39025.5ORDER BY prt_released DESC SELECT * FROM  #tbl'EXEC (@s)SET ROWCOUNT 0ENDGO partslist 10 , '10.10.2006 10:10:10' -- This is just to test the SP.
This code may not be syntatically correct, it's a re-edited version of my code which works fine in my DB.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved