Showing posts with label range. Show all posts
Showing posts with label range. Show all posts

Tuesday, March 20, 2012

Case Expression within a Stored Proc

Is it possible? I have a request to create a stored proc that will
dynamically add a range to a WHERE clause based on a numeric value of a
comment type. If the incoming comment type request is say 10, the
where clause needs to be set to IN(10,11,12,13,14,15,16,17,18,19)OR if
a 20 is passed in the clause would read IN(20,21....)
So I was thinking that a CASE expression within the proc would be the
best way to go, but have had no luck in finding an example or any other
related information regarding CASE exp in a proc.
TIA
BillOn 8 Sep 2004 06:44:18 -0700, Bill Willyerd wrote:

>Is it possible? I have a request to create a stored proc that will
>dynamically add a range to a WHERE clause based on a numeric value of a
>comment type. If the incoming comment type request is say 10, the
>where clause needs to be set to IN(10,11,12,13,14,15,16,17,18,19)OR if
>a 20 is passed in the clause would read IN(20,21....)
>So I was thinking that a CASE expression within the proc would be the
>best way to go, but have had no luck in finding an example or any other
>related information regarding CASE exp in a proc.
>TIA
>Bill

Hi Bill,

In this case (no pun intended), I'd simply write it like this:

WHERE MyColumn BETWEEN @.parameter AND @.parameter + 9

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 8 Sep 2004 08:17:57 -0700, Bill Willyerd wrote:

>Sorry I didn't add that if a request for specfic comment type comes in
>like 22 we only return the type 22's.
>I do like the BETWEEN stmt though I haven't seen that before, I will
>remember that one.
>Thx, Bill

Hi Bill,

Is the request for "a specific comment type" passed in through a seperate
parameter? And the other parameter is used to get a range of comment
types?

CREATE PROC MyProc @.Specific int,
@.RangeStart int
AS
IF (@.Specific IS NULL AND @.RangeStart IS NULL)
OR (@.Specific IS NOT NULL AND @.RangeStart IS NOT NULL)
RAISERROR ('Supply exactly one of the two parameters', 16, 1)
ELSE
IF @.Specific IS NOT NULL
SELECT Column List
FROM YourTable
WHERE MyColumn = @.Specific
ELSE
SELECT Column List
FROM YourTable
WHERE MyColumn BETWEE @.RangeStart AND @.RangeStart + 9
go
(untested)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||On 8 Sep 2004 16:28:26 -0700, Bill Willyerd wrote:

>At present it comes as a single request.
(snip)

Hi Bill,

How do you know if the request is for a specific comment type or for a
range? Surely, there has to be some way to distinguish a request for
comment type '20' (meaning just 20) from a request for comment type '20'
(meaning all values 20 through 29).

Maybe this is a good time to explain what information should be included
in newsgroup postings to maximise the chance to get a useful reply:

* Table structure, posted as DDL (CREATE TABLE statements, omitting
irrelevant columns but including all constraints);
* Sample data, posted as INSERT statements (and please verify that the
CREATE TABLE and INSERT statements you post work properly in an empty test
database!);
* Expected output, based on sample data;
* The SQL code you already got (if any), plus the results these give you
and the reason why that is wrong. If you get an error message, copy and
paste the full message;
* A short, concise description of the business problem you're trying to
solve.

Check out these sites as well:
http://www.aspfaq.com/etiquette.asp?id=5006
http://vyaskn.tripod.com/code.htm#inserts

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Sunday, March 11, 2012

Cascading Parameter issues

Hi all,
SSRS 2005
I have a Time Range parameter that has values
1 - This Week
2 - This Month
3 - This Quarter
4 - This Year
5 - Previous Week
6 - Previous Month
7 - Previous Quarter
8 - Previoous Year
I have 2 other parameters (Start and End Date) that are dependant upon what
they select in the Time Range.
TimeRange "1" is the default and is selected and StartDate shows "3/18/2007"
and EndDate shows "3/24/2007".
The problem is that I want the user to be able to override the dates that
are displayed in the Start and End Date parameters.
To do this, I have Set Start end End Data parameters with "Available Values"
set to Non-Queried and the "Default Values" set to "From Query".
When I first go to run the query, everything looks fine.
If I change the TimeRange to "2" ("This Month"), the Default Start and End
Dates do not update and stay at the dates initially loaded.
Thanks in advance for all your help.
Chris E.On Mar 23, 10:39 am, "Chris" <cex...@.enableconsulting.com> wrote:
> Hi all,
> SSRS 2005
> I have a Time Range parameter that has values
> 1 - This Week
> 2 - This Month
> 3 - This Quarter
> 4 - This Year
> 5 - Previous Week
> 6 - Previous Month
> 7 - Previous Quarter
> 8 - Previoous Year
> I have 2 other parameters (Start and End Date) that are dependant upon what
> they select in the Time Range.
> TimeRange "1" is the default and is selected and StartDate shows "3/18/2007"
> and EndDate shows "3/24/2007".
> The problem is that I want the user to be able to override the dates that
> are displayed in the Start and End Date parameters.
> To do this, I have Set Start end End Data parameters with "Available Values"
> set to Non-Queried and the "Default Values" set to "From Query".
> When I first go to run the query, everything looks fine.
> If I change the TimeRange to "2" ("This Month"), the Default Start and End
> Dates do not update and stay at the dates initially loaded.
> Thanks in advance for all your help.
> Chris E.
It seems like once you change the Time Range parameter value, you are
now using the Available Values/Non-Queried option for the Start and
End Date parameters. I would suggest having 2 additional parameter
options for the user to be allowed to enter in their own values for
Start Date and End Date, defaulting to empty strings; and control the
overriding at the database level (in the stored procedure or query
that is sourcing the report). Hope this is helpful.
Regards,
Enrique Martinez
Sr. SQL Server Developer|||Try instead of non queried, if possible, put the date range in a query so it
will refresh, whenever you select the time range.
Amarnath, MCTS
"Chris" wrote:
> Hi all,
> SSRS 2005
> I have a Time Range parameter that has values
> 1 - This Week
> 2 - This Month
> 3 - This Quarter
> 4 - This Year
> 5 - Previous Week
> 6 - Previous Month
> 7 - Previous Quarter
> 8 - Previoous Year
> I have 2 other parameters (Start and End Date) that are dependant upon what
> they select in the Time Range.
> TimeRange "1" is the default and is selected and StartDate shows "3/18/2007"
> and EndDate shows "3/24/2007".
> The problem is that I want the user to be able to override the dates that
> are displayed in the Start and End Date parameters.
> To do this, I have Set Start end End Data parameters with "Available Values"
> set to Non-Queried and the "Default Values" set to "From Query".
> When I first go to run the query, everything looks fine.
> If I change the TimeRange to "2" ("This Month"), the Default Start and End
> Dates do not update and stay at the dates initially loaded.
> Thanks in advance for all your help.
> Chris E.
>
>

Cascading Parameter issue with RS2005... It worked in RS2000

Our company is attempting to convert several RS2000 reports to RS2005. We have 4 default parameters on every report.

1) Date Range (dropdown) – populated via Non-Queried Available values (Ex. Today, Week to Date, Month to Date, Fiscal Period)
2) Fiscal Period (cascading dropdown) – populated via Query Available values (if Date Range = ‘Fiscal Period’, select the last 24 fiscal months, else select Date Range value)
3) Start Date (cascading textbox) – populated via Query Default values (depending on Fiscal Period value calculate Start Date)
4) End Date (cascading textbox) – populated via Query Default values (depending on Fiscal Period value calculate End Date)

The user starts by selecting a Date Range which auto populates the Fiscal Period the auto populates the 2 Date textboxes. This works great in RS2000; however it’s not 100% in RS2005. Here’s what happens:

If a user selects ‘Today’ or ‘Month to Date’ in Date Range, everything works fine. At this point there is only 1 value in Fiscal Period dropdown. If the user selects ‘Fiscal Period’ in the Date Range, the Fiscal Period is populated with 24 values (1 for the last 24 fiscal months) and is set to the top value (June – 2006). The 2 Date textboxes are also populated correctly.

The problem is when the user changes the value in the Fiscal Period dropdown. Let's say the pick 'Mar - 2004'. The 2 Date fields are not refreshed or updated. If the user changes the selection back in the first dropdown (Date Range), everything is refreshed and updated appropriately. I don’t under stand why the first dropdown will refresh all the dependent parameters but the second dropdown won’t refresh the 2 Date fields below it?

Any input would be very helpful. I’ve tested this on 3 different development boxes and 2 different RS2005 servers. All tests had the same results.

Thanks,
Nick

Any ideas why this thing works in RS2000, but not in RS2005? Any input would be valued. Thanks,

Nick

Thursday, March 8, 2012

Cascade updates

I ran a bulk update on a SQL database for a range between dateswhere there
were trigger and possibly foreign keys. the parent updated fine but it
changed multiple child records although they were not relatedHi
Can you show us DDL + sample data + your query?
"Dangerfield" <Dangerfield@.discussions.microsoft.com> wrote in message
news:2E57BC94-A3B0-46CA-9349-C2DEB7C79F46@.microsoft.com...
> I ran a bulk update on a SQL database for a range between dateswhere there
> were trigger and possibly foreign keys. the parent updated fine but it
> changed multiple child records although they were not related