Showing posts with label parameters. Show all posts
Showing posts with label parameters. Show all posts

Wednesday, March 28, 2012

Putting @Parameters in Stored Procedures

I am creating a stored Procedure and I am getting an error which relates toDATENAME.

SELECTCOUNT(*)AScalls,DATENAME(@.varDate, CALLSTARTTIME)AS 'Total Calls'

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS='1')AND(CALLSTARTTIME >= @.StartDate)AND(CALLENDTIME <=@.EndDate

sql doesn't like: DATENAME( @.varDate, CallStartTime)
sql works fine if I change @.varDate into 'yy', 'mm', 'dd', or 'wk'
Since I do not want to make 5 unique Stored Proc just because of @.varDate....

Is there any way to work around this problem?



Well, you could do something like this:
DECLARE @.varDate VARCHAR(10)
SELECT @.varDate = 'mm'
SELECT
OrderDate,
CASE @.varDate
WHEN 'mm' THEN DATENAME(mm,OrderDate)
WHEN 'yy' THEN DATENAME(yy,OrderDate)
WHEN 'dw' THEN DATENAME(dw,OrderDate)
END -- added this as an EDIT to my post
FROM Orders

|||I tried,

ALTER PROCEDURE dbo.GET_TOTALCALLS
(
@.VarDate as char,
@.StartDate as char,
@.EndDate as char
)
AS
SELECT
COUNT(*) AS 'Calls',
CASE @.VarDate
When 'yy' Then DATEPART(yy, CALLSTARTTIME) AS 'Year'
FROM CALL_LOG_MASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME IS NOT NULL) AND (CALLENDTIME IS NOT NULL)
GROUP BY DATEPART(yy, CALLSTARTTIME)
ORDER BY DATEPART(yy, CALLSTARTTIME)
SQL wouldn't allow me to save. What did I do wrong?
|||Somehow when I coped and pasted my test code I left out an END, sorry about that!
Try it like this:
SELECT
COUNT(*) AS 'Calls',
CASE @.VarDate
When 'yy' Then DATEPART(yy, CALLSTARTTIME)ENDAS 'Year'

FROM CALL_LOG_MASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME IS NOT NULL) AND (CALLENDTIME IS NOT NULL)
GROUP BY DATEPART(yy, CALLSTARTTIME)
ORDER BY DATEPART(yy, CALLSTARTTIME)

Also, in the future, you need to be more specific than "SQL wouldn'tallow me to save". Exact error messages go a long way to gettingexact help.
|||thanks for the advice.
got another error:
ADO error: Column 'Call_LOG_MASTER.CALLSTARTTIME' is invalid in theselect list because it is not contained in either an aggregate functionor the GROUP BY clause.

SELECT
CASE @.varDate
when 'yy' Then DATEPART(yy, CALLSTARTTIME) END as 'Year',
COUNT(DATEPART(yy, CALLSTARTTIME)) AS 'Calls'
FROM CALL_LOG_MASTER
WHERE (COMMERCIALS = '1')AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY DATEPART(yy, CALLSTARTTIME)
ORDER BY DATEPART(yy, CALLSTARTTIME)
|||

I think I found the problem,

ALTER PROCEDUREdbo.GET_TOTALCALLS

(

@.varDateas varchar(255),

@.StartDateas datetime,

@.EndDateas datetime

)

AS

SELECT

CASE@.varDate

When'Year'Then DATEPART(yy, CALLSTARTTIME)

When'Month'Then DATEPART(mm, CALLSTARTTIME)

When'Week'Then DATEPART(wk, CALLSTARTTIME)

When'Day'Then DATEPART(dd, CALLSTARTTIME)

when'Quarter'Then Datepart(qq, CALLSTARTTIME)

END,

Count(*)as'Total Calls'

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(CALLSTARTTIME >= @.StartDate)AND(CALLENDTIME <= @.EndDate)

GROUP BY

CASE@.varDate

When'Year'Then DATEPART(yy, CALLSTARTTIME)

When'Month'Then DATEPART(mm, CALLSTARTTIME)

When'Week'Then DATEPART(wk, CALLSTARTTIME)

When'Day'Then DATEPART(dd, CALLSTARTTIME)

when'Quarter'Then Datepart(qq, CALLSTARTTIME)

End

ORDER BY

CASE@.varDate

When'Year'Then DATEPART(yy, CALLSTARTTIME)

When'Month'Then DATEPART(mm, CALLSTARTTIME)

When'Week'Then DATEPART(wk, CALLSTARTTIME)

When'Day'Then DATEPART(dd, CALLSTARTTIME)

when'Quarter'Then Datepart(qq, CALLSTARTTIME)

End

RETURN

However, the column can't be named this way. My new question is how do I renamed the datepart column by case?
Namely,
when @.varDate = 'Year', the column name should be 'Year',
when @.varDate = 'Month', the column name should be as 'Month', etc..

|||still stuck on this problem, could use some help if possible =)|||If that is your requirement, then I would scrap what you have and just do something like this:
ALTER PROCEDURE dbo.GET_TOTALCALLS
(
@.varDate as varchar (255),
@.StartDate as datetime,
@.EndDate as datetime
)
AS
IF @.varDate = 'Year'
BEGIN
SELECT
DATEPART(yy, CALLSTARTTIME) AS Year,
Count(*) as 'Total Calls'
FROM CALL_LOG_MASTER
WHERE (COMMERCIALS = '1')AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY DATEPART(yy, CALLSTARTTIME)
ORDER BY 1
END
IF @.varDate = 'Month'
BEGIN
SELECT
DATEPART(mm, CALLSTARTTIME) AS Month,
Count(*) as 'Total Calls'
FROM CALL_LOG_MASTER
WHERE (COMMERCIALS = '1')AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY DATEPART(mm, CALLSTARTTIME)
ORDER BY 1
END
-- etc
RETURN

|||yes, thank you. That will work fine

Friday, March 9, 2012

Publishing from RS 2000 to RS 2005

I want to publishing many reports from RS 2000 to RS 2005. These reports have
several server parameters. In order to do it I have used the utility
RSScripter, but this application produces .rss and .cmd files for RS 2000. I
have modified their code to do to function them to publish to RS 2005. Does
exist another version of this utility to do this migration? Does exist
another manner to solve this issue?
Many thanksI prefer to deploy using the report designer. The utility you are speaking
of has a version that supports both 2000 and 2005.
http://www.sqldbatips.com/showarticle.asp?ID=62
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
>I want to publishing many reports from RS 2000 to RS 2005. These reports
>have
> several server parameters. In order to do it I have used the utility
> RSScripter, but this application produces .rss and .cmd files for RS 2000.
> I
> have modified their code to do to function them to publish to RS 2005.
> Does
> exist another version of this utility to do this migration? Does exist
> another manner to solve this issue?
> Many thanks|||I have tried the version 2.0.0.10 and I have downloaded the next version of
RSScripter. When I launch the cmd files produces for RS 2000 to publish to RS
2005 I have some errors if before I don't modified the scripts. In particular,
I can lost the server parameters of RS 2000 reports. Moreover, there are two
different manners between RS 2000 and RS 2005 to set the data source for a
report. I don't see any option inside RSScripter to produce rdl, rds and cmd
files to RS 2005 but reading RS 2000 reports.
"Bruce L-C [MVP]" wrote:
> I prefer to deploy using the report designer. The utility you are speaking
> of has a version that supports both 2000 and 2005.
> http://www.sqldbatips.com/showarticle.asp?ID=62
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
> news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
> >I want to publishing many reports from RS 2000 to RS 2005. These reports
> >have
> > several server parameters. In order to do it I have used the utility
> > RSScripter, but this application produces .rss and .cmd files for RS 2000.
> > I
> > have modified their code to do to function them to publish to RS 2005.
> > Does
> > exist another version of this utility to do this migration? Does exist
> > another manner to solve this issue?
> >
> > Many thanks
>
>|||Ahh, it probably works mostly for moving between the same versions.
If you are going between RS 2000 and RS 2005 I suggest you do not do it this
way. Although RS 2005 will run RS 2000 reports I recommend that you convert
your reports to RS 2005 first. I had a few weird little problems that went
away once I did this.
To convert you have to pull up the report in RS2005 report designer, let it
convert and then save. It is a little bit of a pain but the process is
quick. I kept a copy of my RS 2000 version reports around.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
news:6ED58430-5A33-4DC5-B5EE-1C7FB9F1D8D5@.microsoft.com...
>I have tried the version 2.0.0.10 and I have downloaded the next version of
> RSScripter. When I launch the cmd files produces for RS 2000 to publish to
> RS
> 2005 I have some errors if before I don't modified the scripts. In
> particular,
> I can lost the server parameters of RS 2000 reports. Moreover, there are
> two
> different manners between RS 2000 and RS 2005 to set the data source for a
> report. I don't see any option inside RSScripter to produce rdl, rds and
> cmd
> files to RS 2005 but reading RS 2000 reports.
>
> "Bruce L-C [MVP]" wrote:
>> I prefer to deploy using the report designer. The utility you are
>> speaking
>> of has a version that supports both 2000 and 2005.
>> http://www.sqldbatips.com/showarticle.asp?ID=62
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "Pasquale" <Pasquale@.discussions.microsoft.com> wrote in message
>> news:40E876D4-4EE6-4236-A3B3-03EA3960FE3E@.microsoft.com...
>> >I want to publishing many reports from RS 2000 to RS 2005. These reports
>> >have
>> > several server parameters. In order to do it I have used the utility
>> > RSScripter, but this application produces .rss and .cmd files for RS
>> > 2000.
>> > I
>> > have modified their code to do to function them to publish to RS 2005.
>> > Does
>> > exist another version of this utility to do this migration? Does exist
>> > another manner to solve this issue?
>> >
>> > Many thanks
>>

Wednesday, March 7, 2012

publishing a report with parameters

say if i have a report that takes 2 parameters, StartDate & EndDate. and i want to publish/deploy this report for other users to run. Will the user be prompted to enter the 2 dates when they attempt to run the report?

sorry for the "what if" type question. ive been asked to do a bit of research on SQL Reporting Services

Cheers,
Craig

This depends on the report setup and on the method of access.

By report setup I mean the parameter. You can configure these with defaults and hence the users won't need to select the values but will still have the option to change the defaults.

By method of access I mean whether you are using the report manager (or some equivalent method of URL access) or the ReportServerWebService.Render method. By using URL access you get the "out of the box" export toolbar and parameter toolbar. By using the web service you pass in the paramaeter values but do not get the mentioned toolbars.

Remember, parameter defaults can be query based so for dates this can be made to return a dynamic value such as the current date.

Published Reports -- URGENT

Hi
I am trying to supply input parameters to a report from an aspx page. I tried many methods , but none seem to be working.
Can anyone suggest how I can work with parameterized reports from code?
Moreover , Do I have to publish a report to be able to supply Report Parameters from the code?
Thanks
--
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.You always have to publish a report to the server before you can use it. Not
sure what you are trying to do.
Are you using URL Access or the SOAP API? Supplying paramters to each is
described in BOL.
--
Brian Welcker
Group Program Manager
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"SqlJunkies User" <User@.-NOSPAM-SqlJunkies.com> wrote in message
news:uOaURsuZEHA.3112@.TK2MSFTNGP09.phx.gbl...
> Hi
> I am trying to supply input parameters to a report from an aspx page. I
> tried many methods , but none seem to be working.
> Can anyone suggest how I can work with parameterized reports from code?
> Moreover , Do I have to publish a report to be able to supply Report
> Parameters from the code?
> Thanks
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine
> supports Post Alerts, Ratings, and Searching.|||Hi
This is what i think.
1) in your .aspx page, you would have a hyperlink or something that links to the targeted report Eg:
<a href="http://links.10026.com/?link=http://localhost/Reportserver?/report1¶m1=123" >Go to report1</a>
2) In report1.rdl, you would have created a parameter called param1.
3) You definitely need to publish your report. You do this through the report manager: upload.
Chiara
"SqlJunkies User" wrote:
> Hi
> I am trying to supply input parameters to a report from an aspx page. I tried many methods , but none seem to be working.
> Can anyone suggest how I can work with parameterized reports from code?
> Moreover , Do I have to publish a report to be able to supply Report Parameters from the code?
> Thanks
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
>