Tuesday, March 20, 2012
CASE in where clause?
add WHERE conditions if (and only if) values are sent to it. For example:
SELECT ID, Person
FROM People
WHERE LastName LIKE '%@.var1%' +
CASE WHEN @.var2 IS NOT NULL THEN ' AND TypeCode = ' + @.var2
ELSE ''
END
...etc
Is this possible? Thanks
David> SELECT ID, Person
> FROM People
> WHERE LastName LIKE '%@.var1%' +
> CASE WHEN @.var2 IS NOT NULL THEN ' AND TypeCode = ' + @.var2
> ELSE ''
> END
Did you mean:
SELECT ID, Person
FROM People
WHERE LastName LIKE '%' + @.var1 + '%'
AND TypeCode = COALESCE(@.TypeCode, TypeCode)
or more verbosely
SELECT ID, Person
FROM People
WHERE LastName LIKE '%' + @.var1 + '%'
AND TypeCode = CASE WHEN @.TypeCode IS NULL THEN TypeCode ELSE @.TypeCode END
CASE is an expression that returns a single value. It is *NOT* used for
flow control.|||could I suggest a slight amendment (and add a question):
SELECT ID, Person
FROM People
WHERE LastName LIKE '%' + @.var1 + '%'
AND (@.TypeCode is null OR TypeCode = @.TypeCode)
this way when @.typecode is null the lazy evaluation of SQL will mean it
won't even look at the second statement.
I've found if it's put the other way:
WHERE Typecode = @.TypeCode OR @.TypeCode is null
it will first evaluation Typecode = @.TypeCode, causing it to scan that
field, then it will evaluate the second statement.
I'm not sure but I suspect your suggestion of Typecode =
COALLESCE(@.TypeCode, TypeCode) will cause it to read the typecode field
even when a null value is passed to it.
Cheers
Will|||> I've found if it's put the other way:
> WHERE Typecode = @.TypeCode OR @.TypeCode is null
> it will first evaluation Typecode = @.TypeCode, causing it to scan that
> field, then it will evaluate the second statement.
There is no guarantee in the order of execution within a clause, it could go
left to right, it could go right to left.
> I'm not sure but I suspect your suggestion of Typecode =
> COALLESCE(@.TypeCode, TypeCode) will cause it to read the typecode field
> even when a null value is passed to it.
Really hard to say without table structure, sample data, row counts, and the
ability to actually test and examine query plans.|||"There is no guarantee in the order of execution within a clause, it
could go
left to right, it could go right to left. "
I know you're an MVP, and do indeed know SQL server way better than me,
but still I feel I have to ask - are you sure about this?
it's just that I've found on several occasions that if I switch the 2
statements around it changes the execution plan fundamentally, and
doesn't do any table scans (when the value is null of course). If the
order was not an issue then surely switching the order would not affect
the query?
Thanks
Will|||> it's just that I've found on several occasions that if I switch the 2
> statements around it changes the execution plan fundamentally, and
> doesn't do any table scans (when the value is null of course). If the
> order was not an issue then surely switching the order would not affect
> the query?
I didn't say order CAN'T be an issue. Just don't rely on this kind of
short-circuiting to work consistently.|||Fundamental mistake! There is no CASE **statement** in SQL. There is
a CASE **expression**; remember programming 101? Expressions return
scalar values, not control of execution flow.
SELECT person_id, person_name
FROM People
WHERE last_name LIKE '%' + @.var1 + '%'
AND foobar_code = COALESCE(@.my_code, foobar_code) ;
Even for an example, you had some pretty awful data element names.
Something can be a type of something or a code. It cannot be both.
There is no such thing as just an "id" -- it has to identify something
in particular.
You might want to get a book on SQL and data modeling.|||Will (william_pegg@.yahoo.co.uk) writes:
> could I suggest a slight amendment (and add a question):
> SELECT ID, Person
> FROM People
> WHERE LastName LIKE '%' + @.var1 + '%'
> AND (@.TypeCode is null OR TypeCode = @.TypeCode)
> this way when @.typecode is null the lazy evaluation of SQL will mean it
> won't even look at the second statement.
It's unclear here what you mean with "second statement".
@.TypeCode IS NULL OR TypeCode = @.TypeCode
would be the same as
TypeCode = @.TypeCode OR @.TypeCode IS NULL
when it comes to performance.
If you've seen something else, it might have been a mirage due to
caching.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||My Apologies,
I really should stop questioning MVPs, you guys don't ever seem to be
wrong. I tried to recreate the situation and couldn't. My reasoning was
based on several queries I've debugged in the past that were displaying
a strange execution plan, and then by switching the statements around
(the "or" statements), increased performance dramatically (from 4s to
50ms). I assumed at the time that it was just a simple grammar case
that you could apply lazy evaluation, and that was how SQL was
optimising it, however it appears that there's more stuff going on.
perhaps the optimiser was having an odd day, or more likely there were
incorrect index statistics monkeying things up, but anyway, thanks for
clearing it up.
Cheers
Will|||The problem is that SQL is set-oriented and not sequential. The THEN
clauses in a CASE expression (which includes COALESCE()) all have to be
evaluated to determine the data type of the whole expression. It does
not matter if some of them are unreachable.
COALESCE correctly promotes its arguments to the highest data type in
the expression:
13 / COALESCE(CAST(NULL AS INTEGER), 2.00) = 6.5
The proprietary ISNULL() uses the first data type and gets things wrong
13 / ISNULL(CAST(NULL AS INTEGER), 2.00) = 6
You would need to write:
13 / ISNULL(CAST(NULL AS DECIMAL(4,2)), 2.00)sql
Case Expression within a Stored Proc
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)
case expression stor proc, need some help
(
@.varDate as varchar (255),
@.StartDate as datetime,
@.EndDate as datetime
)
AS
SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME)
END,
COUNT(*) as 'Total Calls'
FROM CALLMASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
WHEN 'Month' Then DATEPART(mm, CALLSTARTTIME), DATENAME(mm, CALLSTARTTIME) ' <--this part gave me an error, because of the comma,
END
ORDER BY
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
WHEN 'Month' Then DATEPART(mm, CALLSTARTTIME)
END
The month case is giving me an error. I think it has to do with two expressions in one line.
Anyone know how to combine that into 1 expression? or is there away to work around it?
As I would like to display the month as Name, but group and sort by number.
Thx!~Are you saying you don't get the data you want if you remove the datename part from your group by clause? You are getting the month name out by the select part of your procedure and I don't see the need to also group by it if you only want to group by number.|||well, I am trying to get data displayed in the name of the month, but not in ABC order.
i.e.
January
Feb
March
instead of ABC order,
April
December
Febuary
I did the sql before grouping them together.
And this worked,
SELECT
DATENAME(mm, CALLSTARTTIME),
COUNT(*) as 'Total Calls'
FROM CALLMASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY
DATEPART(mm, CALLSTARTTIME), DATENAME(mm, CALLSTARTTIME)
ORDER BY
DATEPART(mm, CALLSTARTTIME)
Yet, the GROUP BY clause consist oftwoexpressions for it to function, (from my understanding)
and I don't know how to make that clause work in a CASE expression.
Thx in advance~|||oh yea, this doesn't work from my understanding:
SELECT
DATENAME(mm, CALLSTARTTIME),
COUNT(*) as 'Total Calls'
FROM CALLMASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY
DATENAME(mm, CALLSTARTTIME)
ORDER BY
DATEPART(mm, CALLSTARTTIME)|||How about this:-
GROUP BY
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
WHEN 'Month' Then DATEPART(mm, CALLSTARTTIME)
END,
CASE @.varDate
WHEN 'Year' Then ??
WHEN 'Quarter' Then ??
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME)
END
I think it would only work if you could put something in for the Year and Quarter too (where the ?? are). Might not work at all.
The only other thing would be to perhaps use a sql if to have 2 different selects, one for month with case no longer needed and one for the other 2 using case:-
if @.varDate='Month'
begin
SELECT DATENAME(mm, CALLSTARTTIME), COUNT(*) as 'Total Calls'
FROM CALLMASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY
DATEPART(mm, CALLSTARTTIME), DATENAME(mm, CALLSTARTTIME)
ORDER BY
DATEPART(mm, CALLSTARTTIME)
end
else
begin
SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
END,
COUNT(*) as 'Total Calls'
FROM CALLMASTER
WHERE (COMMERCIALS = '1') AND (CALLSTARTTIME >= @.StartDate) AND (CALLENDTIME <= @.EndDate)
GROUP BY
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
END
ORDER BY
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME)
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)
END
end|||Thank you Brian. That will work.
Side Question: is there a way to name the heading by case?
e.g.
SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME) <--This will have As 'Year'
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)<--This will have As 'Quarter'
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME) <--This will have as 'Month'
END,|||Yes there is:-
SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME) <--This will have As 'Year'
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)<--This will have As 'Quarter'
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME) <--This will have as 'Month'
END as myheadingname|||SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME) <--This will have As 'Year'
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME)<--This will have As 'Quarter'
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME) <--This will have as 'Month'
END as myheadingname
Can myheadingname varies by case? like can it be a parameter/variable,and it will display different headings depending on the case selected.
e.g.
When @.varDate = 'Year', the column header will be 'Year'.
When @.varDate = 'Month', the column header will be 'Month'.
When @.varDate = 'Quarter', the column header will be 'Quarter'
the above example, as myheadingname is a generalized header. It will not differ no matter what @.varDate is.|||I don't think you can but no harm in trying something like that:-
SELECT
CASE @.varDate
WHEN 'Year' Then DATEPART(yy, CALLSTARTTIME) As 'Year'
WHEN 'Quarter' Then DATENAME(qq, CALLSTARTTIME) As 'Quarter'
WHEN 'Month' Then DATENAME(mm, CALLSTARTTIME) as 'Month'
END
You will probably get an error if it doesn't work.|||yup, got an error.|||Well other than that you can expand the if for each possibility and do without the case.
Case conversion with SQL or Stored Proc
Hi experts,
I m new in SQL stuff. I have to work out a fucntion with ASP.net for CSV import to the DB in MSSQL.
I would like to know for Stored Proc, is there any way that I can do the case conversion?
e.g
the Full_Name read from CSV file: Lennon, John
Then for the family name I need to convert into uppercase so the converted one: LENNON, John
Is there any way I can check those words before the comma? The CSV file is delimited with | instead of , ?
Can I use substring for that? And also do you have any online tutorial for Stored Procedure recommended? Thanks a lot!!!
Cheers,
KNVB
Hi,
Here is an example:
declare @.fullName varchar(100)
set @.fullName = 'Lennon, John'
select upper(left(@.fullName, charindex(',', @.fullName) - 1)) + right(@.fullName, len(@.fullName) - charindex(',', @.fullName) + 1)
Note: The first two lines of code are just for the sample
It might be better to implement this as a FUNCTION in case of a STORED PROCEDURE since functions can be used in your select statement.
References:
Creating stored procedures: http://www.sql-server-performance.com/tn_stored_procedures.asp|||
Merci beaucoup, Geert!
By the way, have you heard of a company called i4net from Namur?
|||No problem, glad to help.
I didn’t know i4net. Is this your company maybe?
Greetz,
Geert
Sunday, March 11, 2012
cascading parameters
Can I use them with stored procs and how?
I have one main stored proc and many smaller ones for the parameters.
I seem to be missing where to link them?Cascading parameters means one parameter is dependant on a different
parameter.
Like you have to choose a Country before a drop down list of Cities in that
country gets selectable.
You make cascading parameters by having the query for the second parameter
take the value of the selected item of the first parameter as a parameter.
Pseudocode:
Parameter 1 - Country
Select CountryID, CountryName from Country
- Parameter Value = CountryID, Parameter Label = CountryName
Parameter 2:
Select CityID, CityName from City where CountryID = Parameters!Country.Value
When you connect parameters, you won't be able to choose a city before
you've chosen a country.
You link the second parameter to the first just as you would link a data set
to the parameters.
Kaisa M. Lindahl Lervik
"ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
news:35B6AA90-3871-4DA5-A05D-B1BDD9E8EB33@.microsoft.com...
>I am a little confused on these cascading parameters.
> Can I use them with stored procs and how?
> I have one main stored proc and many smaller ones for the parameters.
> I seem to be missing where to link them?
>|||Thank you for the reply.
I am using stored procs everywhere and having a time trying to link them.
I can get part of the parameter to do what I want it's at execution it fails
to work.
Will try to make my parameters link, currently there is no relationship. If
you select a certain group you get a set of med conditions and they are not
tied to each other on the backend?
Will keep trying though...thx again..it was very helpful.
"Kaisa M. Lindahl Lervik" wrote:
> Cascading parameters means one parameter is dependant on a different
> parameter.
> Like you have to choose a Country before a drop down list of Cities in that
> country gets selectable.
> You make cascading parameters by having the query for the second parameter
> take the value of the selected item of the first parameter as a parameter.
> Pseudocode:
> Parameter 1 - Country
> Select CountryID, CountryName from Country
> - Parameter Value = CountryID, Parameter Label = CountryName
> Parameter 2:
> Select CityID, CityName from City where CountryID = Parameters!Country.Value
> When you connect parameters, you won't be able to choose a city before
> you've chosen a country.
> You link the second parameter to the first just as you would link a data set
> to the parameters.
> Kaisa M. Lindahl Lervik
>
> "ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
> news:35B6AA90-3871-4DA5-A05D-B1BDD9E8EB33@.microsoft.com...
> >I am a little confused on these cascading parameters.
> > Can I use them with stored procs and how?
> > I have one main stored proc and many smaller ones for the parameters.
> > I seem to be missing where to link them?
> >
>
>|||I have something working but what can I set the true property to?
=IIF(left(Parameters!MonGrp.Value,2) = "BB", Nothing,"exec p_GetConditions")
causing an error: ExecuteReader: CommandText property has not been initialized
This is exciting help pls on this last endeavor.
"ATB4U" wrote:
> Thank you for the reply.
> I am using stored procs everywhere and having a time trying to link them.
> I can get part of the parameter to do what I want it's at execution it fails
> to work.
> Will try to make my parameters link, currently there is no relationship. If
> you select a certain group you get a set of med conditions and they are not
> tied to each other on the backend?
> Will keep trying though...thx again..it was very helpful.
> "Kaisa M. Lindahl Lervik" wrote:
> > Cascading parameters means one parameter is dependant on a different
> > parameter.
> > Like you have to choose a Country before a drop down list of Cities in that
> > country gets selectable.
> > You make cascading parameters by having the query for the second parameter
> > take the value of the selected item of the first parameter as a parameter.
> >
> > Pseudocode:
> >
> > Parameter 1 - Country
> > Select CountryID, CountryName from Country
> > - Parameter Value = CountryID, Parameter Label = CountryName
> >
> > Parameter 2:
> > Select CityID, CityName from City where CountryID = Parameters!Country.Value
> >
> > When you connect parameters, you won't be able to choose a city before
> > you've chosen a country.
> > You link the second parameter to the first just as you would link a data set
> > to the parameters.
> >
> > Kaisa M. Lindahl Lervik
> >
> >
> > "ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
> > news:35B6AA90-3871-4DA5-A05D-B1BDD9E8EB33@.microsoft.com...
> > >I am a little confused on these cascading parameters.
> > > Can I use them with stored procs and how?
> > > I have one main stored proc and many smaller ones for the parameters.
> > > I seem to be missing where to link them?
> > >
> >
> >
> >|||You can only cascade (link) parameters that have a relation. That's sort of
the point. What you choose as the value in the first parameter, get sent to
the query for the next parameter as a parameter.
Microsoft has written a tutorial on "Adding cascading parameters to a
report" at
http://msdn2.microsoft.com/en-us/library/aa337426.aspx
You might want to read it to get a clear picture on what it is and how to
use it in your report. :)
Kaisa M. Lindahl Lervik
"ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
news:6FCEEC06-0591-4C4F-B10C-360DEE2B21CD@.microsoft.com...
>I have something working but what can I set the true property to?
> =IIF(left(Parameters!MonGrp.Value,2) = "BB", Nothing,"exec
> p_GetConditions")
> causing an error: ExecuteReader: CommandText property has not been
> initialized
> This is exciting help pls on this last endeavor.
> "ATB4U" wrote:
>> Thank you for the reply.
>> I am using stored procs everywhere and having a time trying to link them.
>> I can get part of the parameter to do what I want it's at execution it
>> fails
>> to work.
>> Will try to make my parameters link, currently there is no relationship.
>> If
>> you select a certain group you get a set of med conditions and they are
>> not
>> tied to each other on the backend?
>> Will keep trying though...thx again..it was very helpful.
>> "Kaisa M. Lindahl Lervik" wrote:
>> > Cascading parameters means one parameter is dependant on a different
>> > parameter.
>> > Like you have to choose a Country before a drop down list of Cities in
>> > that
>> > country gets selectable.
>> > You make cascading parameters by having the query for the second
>> > parameter
>> > take the value of the selected item of the first parameter as a
>> > parameter.
>> >
>> > Pseudocode:
>> >
>> > Parameter 1 - Country
>> > Select CountryID, CountryName from Country
>> > - Parameter Value = CountryID, Parameter Label = CountryName
>> >
>> > Parameter 2:
>> > Select CityID, CityName from City where CountryID =>> > Parameters!Country.Value
>> >
>> > When you connect parameters, you won't be able to choose a city before
>> > you've chosen a country.
>> > You link the second parameter to the first just as you would link a
>> > data set
>> > to the parameters.
>> >
>> > Kaisa M. Lindahl Lervik
>> >
>> >
>> > "ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
>> > news:35B6AA90-3871-4DA5-A05D-B1BDD9E8EB33@.microsoft.com...
>> > >I am a little confused on these cascading parameters.
>> > > Can I use them with stored procs and how?
>> > > I have one main stored proc and many smaller ones for the parameters.
>> > > I seem to be missing where to link them?
>> > >
>> >
>> >
>> >|||Here's the great thing!
I got this to work, conditional data set.
=IIF(left(Parameters!MonGrp.Value,2) = "BB",Nothing,"exec p_GetConditions")
What I am looking for now if the user selects BB, I need to hide the
condition parameter...something in the "Nothing" piece that diables the
condition parameter.
Thank you for all your help, but I have to get this b/c it will be needed
throuhout all of my reports.
"Kaisa M. Lindahl Lervik" wrote:
> You can only cascade (link) parameters that have a relation. That's sort of
> the point. What you choose as the value in the first parameter, get sent to
> the query for the next parameter as a parameter.
> Microsoft has written a tutorial on "Adding cascading parameters to a
> report" at
> http://msdn2.microsoft.com/en-us/library/aa337426.aspx
> You might want to read it to get a clear picture on what it is and how to
> use it in your report. :)
> Kaisa M. Lindahl Lervik
>
> "ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
> news:6FCEEC06-0591-4C4F-B10C-360DEE2B21CD@.microsoft.com...
> >I have something working but what can I set the true property to?
> > =IIF(left(Parameters!MonGrp.Value,2) = "BB", Nothing,"exec
> > p_GetConditions")
> > causing an error: ExecuteReader: CommandText property has not been
> > initialized
> > This is exciting help pls on this last endeavor.
> >
> > "ATB4U" wrote:
> >
> >> Thank you for the reply.
> >> I am using stored procs everywhere and having a time trying to link them.
> >> I can get part of the parameter to do what I want it's at execution it
> >> fails
> >> to work.
> >> Will try to make my parameters link, currently there is no relationship.
> >> If
> >> you select a certain group you get a set of med conditions and they are
> >> not
> >> tied to each other on the backend?
> >> Will keep trying though...thx again..it was very helpful.
> >>
> >> "Kaisa M. Lindahl Lervik" wrote:
> >>
> >> > Cascading parameters means one parameter is dependant on a different
> >> > parameter.
> >> > Like you have to choose a Country before a drop down list of Cities in
> >> > that
> >> > country gets selectable.
> >> > You make cascading parameters by having the query for the second
> >> > parameter
> >> > take the value of the selected item of the first parameter as a
> >> > parameter.
> >> >
> >> > Pseudocode:
> >> >
> >> > Parameter 1 - Country
> >> > Select CountryID, CountryName from Country
> >> > - Parameter Value = CountryID, Parameter Label = CountryName
> >> >
> >> > Parameter 2:
> >> > Select CityID, CityName from City where CountryID => >> > Parameters!Country.Value
> >> >
> >> > When you connect parameters, you won't be able to choose a city before
> >> > you've chosen a country.
> >> > You link the second parameter to the first just as you would link a
> >> > data set
> >> > to the parameters.
> >> >
> >> > Kaisa M. Lindahl Lervik
> >> >
> >> >
> >> > "ATB4U" <ATB4U@.discussions.microsoft.com> wrote in message
> >> > news:35B6AA90-3871-4DA5-A05D-B1BDD9E8EB33@.microsoft.com...
> >> > >I am a little confused on these cascading parameters.
> >> > > Can I use them with stored procs and how?
> >> > > I have one main stored proc and many smaller ones for the parameters.
> >> > > I seem to be missing where to link them?
> >> > >
> >> >
> >> >
> >> >
>
>
Wednesday, March 7, 2012
Caputre T-SQL Error Message in Stroed Proc
age.
Any help would be appricated.
Thanks in Advanced
Not possible: http://vyaskn.tripod.com/programming_faq.htm#q7
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Jitendra" <Jitendra@.discussions.microsoft.com> wrote in message
news:16CBD76A-C566-407E-A554-945809530259@.microsoft.com...
> I need to capture the exact error message whenever the error occur while
exectuing the SQL query. I am able to get the error code and error message
from sysmessages table but error message contain some input values like
'%ls'. I need to get the exact message.
> Any help would be appricated.
> Thanks in Advanced
|||I dont know if there's a way where the stored proc woudl run to completion
if an error occurs. It would ideally exit and print the message. So unless
you want to say, direct your results (inc error message) to a txt file?
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.
Caputre T-SQL Error Message in Stroed Proc
ctuing the SQL query. I am able to get the error code and error message from
sysmessages table but error message contain some input values like '%ls'. I
need to get the exact mess
age.
Any help would be appricated.
Thanks in AdvancedNot possible: http://vyaskn.tripod.com/programming_faq.htm#q7
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Jitendra" <Jitendra@.discussions.microsoft.com> wrote in message
news:16CBD76A-C566-407E-A554-945809530259@.microsoft.com...
> I need to capture the exact error message whenever the error occur while
exectuing the SQL query. I am able to get the error code and error message
from sysmessages table but error message contain some input values like
'%ls'. I need to get the exact message.
> Any help would be appricated.
> Thanks in Advanced|||I dont know if there's a way where the stored proc woudl run to completion
if an error occurs. It would ideally exit and print the message. So unless
you want to say, direct your results (inc error message) to a txt file?
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.
Saturday, February 25, 2012
Capturing stored proc names in profiler
I was wondering if anyone had some insight into my problem.
I'm running a trace and I want to generate a report to show some simple
statistics about the duration, reads, and writes for the stored procedures
in my database. I'm having trouble parsing the stored procedure name from
the TextData field. The RPC:Completed event gives me everything I need for
the statistics, but it doesn't give me the stored procedure name or object
id. I does, however, give me full command, but I have to parse this with
string manipulation which is not quick. The SP:Completed event gives me the
object id of the stored procedure, but non of the statistics. My trace
files are very large and I'm looking for an easy way to generate some
statistics.
Thanks!
Hi
I assume that you are loading these into a table for analysis, therefore if
you create a new column for the procedure name (and the procedures have a
recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
textdate, then you can use substring and charindex to update the new column.
When you select the data from the table you can restrict the events
returned.
John
"Oliwa" <abc> wrote in message
news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I was wondering if anyone had some insight into my problem.
> I'm running a trace and I want to generate a report to show some simple
> statistics about the duration, reads, and writes for the stored procedures
> in my database. I'm having trouble parsing the stored procedure name from
> the TextData field. The RPC:Completed event gives me everything I need
> for the statistics, but it doesn't give me the stored procedure name or
> object id. I does, however, give me full command, but I have to parse
> this with string manipulation which is not quick. The SP:Completed event
> gives me the object id of the stored procedure, but non of the statistics.
> My trace files are very large and I'm looking for an easy way to generate
> some statistics.
> Thanks!
>
|||Hey John,
That's an idea, but I'm doing something very similar with string
manipulation. I was looking for methods that didn't require string
manipulation.
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
> Hi
> I assume that you are loading these into a table for analysis, therefore
> if you create a new column for the procedure name (and the procedures have
> a recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
> textdate, then you can use substring and charindex to update the new
> column.
> When you select the data from the table you can restrict the events
> returned.
> John
>
> "Oliwa" <abc> wrote in message
> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>
|||Hi
If you are only profiling a single user then you can always check your
object ID from the previous SP:Completed event. Even if not a single user,
then you should be able to match SIDs.
When moving the profile into a table, Profiler will generate a RowNumber
Identity column for you.
John
"Oliwa" <abc> wrote in message news:OGJDUB0JFHA.2648@.TK2MSFTNGP14.phx.gbl...
> Hey John,
> That's an idea, but I'm doing something very similar with string
> manipulation. I was looking for methods that didn't require string
> manipulation.
> Thanks
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
>
Capturing stored proc names in profiler
I was wondering if anyone had some insight into my problem.
I'm running a trace and I want to generate a report to show some simple
statistics about the duration, reads, and writes for the stored procedures
in my database. I'm having trouble parsing the stored procedure name from
the TextData field. The RPC:Completed event gives me everything I need for
the statistics, but it doesn't give me the stored procedure name or object
id. I does, however, give me full command, but I have to parse this with
string manipulation which is not quick. The SP:Completed event gives me the
object id of the stored procedure, but non of the statistics. My trace
files are very large and I'm looking for an easy way to generate some
statistics.
Thanks!Hi
I assume that you are loading these into a table for analysis, therefore if
you create a new column for the procedure name (and the procedures have a
recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
textdate, then you can use substring and charindex to update the new column.
When you select the data from the table you can restrict the events
returned.
John
"Oliwa" <abc> wrote in message
news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I was wondering if anyone had some insight into my problem.
> I'm running a trace and I want to generate a report to show some simple
> statistics about the duration, reads, and writes for the stored procedures
> in my database. I'm having trouble parsing the stored procedure name from
> the TextData field. The RPC:Completed event gives me everything I need
> for the statistics, but it doesn't give me the stored procedure name or
> object id. I does, however, give me full command, but I have to parse
> this with string manipulation which is not quick. The SP:Completed event
> gives me the object id of the stored procedure, but non of the statistics.
> My trace files are very large and I'm looking for an easy way to generate
> some statistics.
> Thanks!
>|||Hey John,
That's an idea, but I'm doing something very similar with string
manipulation. I was looking for methods that didn't require string
manipulation.
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
> Hi
> I assume that you are loading these into a table for analysis, therefore
> if you create a new column for the procedure name (and the procedures have
> a recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
> textdate, then you can use substring and charindex to update the new
> column.
> When you select the data from the table you can restrict the events
> returned.
> John
>
> "Oliwa" <abc> wrote in message
> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>|||Hi
If you are only profiling a single user then you can always check your
object ID from the previous SP:Completed event. Even if not a single user,
then you should be able to match SIDs.
When moving the profile into a table, Profiler will generate a RowNumber
Identity column for you.
John
"Oliwa" <abc> wrote in message news:OGJDUB0JFHA.2648@.TK2MSFTNGP14.phx.gbl...
> Hey John,
> That's an idea, but I'm doing something very similar with string
> manipulation. I was looking for methods that didn't require string
> manipulation.
> Thanks
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
>
Capturing stored proc names in profiler
I was wondering if anyone had some insight into my problem.
I'm running a trace and I want to generate a report to show some simple
statistics about the duration, reads, and writes for the stored procedures
in my database. I'm having trouble parsing the stored procedure name from
the TextData field. The RPC:Completed event gives me everything I need for
the statistics, but it doesn't give me the stored procedure name or object
id. I does, however, give me full command, but I have to parse this with
string manipulation which is not quick. The SP:Completed event gives me the
object id of the stored procedure, but non of the statistics. My trace
files are very large and I'm looking for an easy way to generate some
statistics.
Thanks!
Hi
I assume that you are loading these into a table for analysis, therefore if
you create a new column for the procedure name (and the procedures have a
recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
textdate, then you can use substring and charindex to update the new column.
When you select the data from the table you can restrict the events
returned.
John
"Oliwa" <abc> wrote in message
news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I was wondering if anyone had some insight into my problem.
> I'm running a trace and I want to generate a report to show some simple
> statistics about the duration, reads, and writes for the stored procedures
> in my database. I'm having trouble parsing the stored procedure name from
> the TextData field. The RPC:Completed event gives me everything I need
> for the statistics, but it doesn't give me the stored procedure name or
> object id. I does, however, give me full command, but I have to parse
> this with string manipulation which is not quick. The SP:Completed event
> gives me the object id of the stored procedure, but non of the statistics.
> My trace files are very large and I'm looking for an easy way to generate
> some statistics.
> Thanks!
>
|||Hey John,
That's an idea, but I'm doing something very similar with string
manipulation. I was looking for methods that didn't require string
manipulation.
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
> Hi
> I assume that you are loading these into a table for analysis, therefore
> if you create a new column for the procedure name (and the procedures have
> a recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
> textdate, then you can use substring and charindex to update the new
> column.
> When you select the data from the table you can restrict the events
> returned.
> John
>
> "Oliwa" <abc> wrote in message
> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>
|||Hi
If you are only profiling a single user then you can always check your
object ID from the previous SP:Completed event. Even if not a single user,
then you should be able to match SIDs.
When moving the profile into a table, Profiler will generate a RowNumber
Identity column for you.
John
"Oliwa" <abc> wrote in message news:OGJDUB0JFHA.2648@.TK2MSFTNGP14.phx.gbl...
> Hey John,
> That's an idea, but I'm doing something very similar with string
> manipulation. I was looking for methods that didn't require string
> manipulation.
> Thanks
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
>
Capturing stored proc names in profiler
I was wondering if anyone had some insight into my problem.
I'm running a trace and I want to generate a report to show some simple
statistics about the duration, reads, and writes for the stored procedures
in my database. I'm having trouble parsing the stored procedure name from
the TextData field. The RPC:Completed event gives me everything I need for
the statistics, but it doesn't give me the stored procedure name or object
id. I does, however, give me full command, but I have to parse this with
string manipulation which is not quick. The SP:Completed event gives me the
object id of the stored procedure, but non of the statistics. My trace
files are very large and I'm looking for an easy way to generate some
statistics.
Thanks!Hi
I assume that you are loading these into a table for analysis, therefore if
you create a new column for the procedure name (and the procedures have a
recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
textdate, then you can use substring and charindex to update the new column.
When you select the data from the table you can restrict the events
returned.
John
"Oliwa" <abc> wrote in message
news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I was wondering if anyone had some insight into my problem.
> I'm running a trace and I want to generate a report to show some simple
> statistics about the duration, reads, and writes for the stored procedures
> in my database. I'm having trouble parsing the stored procedure name from
> the TextData field. The RPC:Completed event gives me everything I need
> for the statistics, but it doesn't give me the stored procedure name or
> object id. I does, however, give me full command, but I have to parse
> this with string manipulation which is not quick. The SP:Completed event
> gives me the object id of the stored procedure, but non of the statistics.
> My trace files are very large and I'm looking for an easy way to generate
> some statistics.
> Thanks!
>|||Hey John,
That's an idea, but I'm doing something very similar with string
manipulation. I was looking for methods that didn't require string
manipulation.
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
> Hi
> I assume that you are loading these into a table for analysis, therefore
> if you create a new column for the procedure name (and the procedures have
> a recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
> textdate, then you can use substring and charindex to update the new
> column.
> When you select the data from the table you can restrict the events
> returned.
> John
>
> "Oliwa" <abc> wrote in message
> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>|||Hi
If you are only profiling a single user then you can always check your
object ID from the previous SP:Completed event. Even if not a single user,
then you should be able to match SIDs.
When moving the profile into a table, Profiler will generate a RowNumber
Identity column for you.
John
"Oliwa" <abc> wrote in message news:OGJDUB0JFHA.2648@.TK2MSFTNGP14.phx.gbl...
> Hey John,
> That's an idea, but I'm doing something very similar with string
> manipulation. I was looking for methods that didn't require string
> manipulation.
> Thanks
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
>
Capturing stored proc names in profiler
I was wondering if anyone had some insight into my problem.
I'm running a trace and I want to generate a report to show some simple
statistics about the duration, reads, and writes for the stored procedures
in my database. I'm having trouble parsing the stored procedure name from
the TextData field. The RPC:Completed event gives me everything I need for
the statistics, but it doesn't give me the stored procedure name or object
id. I does, however, give me full command, but I have to parse this with
string manipulation which is not quick. The SP:Completed event gives me the
object id of the stored procedure, but non of the statistics. My trace
files are very large and I'm looking for an easy way to generate some
statistics.
Thanks!Hi
I assume that you are loading these into a table for analysis, therefore if
you create a new column for the procedure name (and the procedures have a
recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
textdate, then you can use substring and charindex to update the new column.
When you select the data from the table you can restrict the events
returned.
John
"Oliwa" <abc> wrote in message
news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
> Hello,
> I was wondering if anyone had some insight into my problem.
> I'm running a trace and I want to generate a report to show some simple
> statistics about the duration, reads, and writes for the stored procedures
> in my database. I'm having trouble parsing the stored procedure name from
> the TextData field. The RPC:Completed event gives me everything I need
> for the statistics, but it doesn't give me the stored procedure name or
> object id. I does, however, give me full command, but I have to parse
> this with string manipulation which is not quick. The SP:Completed event
> gives me the object id of the stored procedure, but non of the statistics.
> My trace files are very large and I'm looking for an easy way to generate
> some statistics.
> Thanks!
>|||Hey John,
That's an idea, but I'm doing something very similar with string
manipulation. I was looking for methods that didn't require string
manipulation.
Thanks
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
> Hi
> I assume that you are loading these into a table for analysis, therefore
> if you create a new column for the procedure name (and the procedures have
> a recognisable prefix e.g 'prc_ ' in the first 8000 characters of the
> textdate, then you can use substring and charindex to update the new
> column.
> When you select the data from the table you can restrict the events
> returned.
> John
>
> "Oliwa" <abc> wrote in message
> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>> Hello,
>> I was wondering if anyone had some insight into my problem.
>> I'm running a trace and I want to generate a report to show some simple
>> statistics about the duration, reads, and writes for the stored
>> procedures in my database. I'm having trouble parsing the stored
>> procedure name from the TextData field. The RPC:Completed event gives me
>> everything I need for the statistics, but it doesn't give me the stored
>> procedure name or object id. I does, however, give me full command, but
>> I have to parse this with string manipulation which is not quick. The
>> SP:Completed event gives me the object id of the stored procedure, but
>> non of the statistics. My trace files are very large and I'm looking for
>> an easy way to generate some statistics.
>> Thanks!
>|||Hi
If you are only profiling a single user then you can always check your
object ID from the previous SP:Completed event. Even if not a single user,
then you should be able to match SIDs.
When moving the profile into a table, Profiler will generate a RowNumber
Identity column for you.
John
"Oliwa" <abc> wrote in message news:OGJDUB0JFHA.2648@.TK2MSFTNGP14.phx.gbl...
> Hey John,
> That's an idea, but I'm doing something very similar with string
> manipulation. I was looking for methods that didn't require string
> manipulation.
> Thanks
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:%23rCtG6zJFHA.3336@.TK2MSFTNGP09.phx.gbl...
>> Hi
>> I assume that you are loading these into a table for analysis, therefore
>> if you create a new column for the procedure name (and the procedures
>> have a recognisable prefix e.g 'prc_ ' in the first 8000 characters of
>> the textdate, then you can use substring and charindex to update the new
>> column.
>> When you select the data from the table you can restrict the events
>> returned.
>> John
>>
>> "Oliwa" <abc> wrote in message
>> news:%23qbnElyJFHA.2576@.TK2MSFTNGP15.phx.gbl...
>> Hello,
>> I was wondering if anyone had some insight into my problem.
>> I'm running a trace and I want to generate a report to show some simple
>> statistics about the duration, reads, and writes for the stored
>> procedures in my database. I'm having trouble parsing the stored
>> procedure name from the TextData field. The RPC:Completed event gives
>> me everything I need for the statistics, but it doesn't give me the
>> stored procedure name or object id. I does, however, give me full
>> command, but I have to parse this with string manipulation which is not
>> quick. The SP:Completed event gives me the object id of the stored
>> procedure, but non of the statistics. My trace files are very large and
>> I'm looking for an easy way to generate some statistics.
>> Thanks!
>>
>