Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Wednesday, March 21, 2012

Query for Distinct Parameter with newest Date

I am having trouble setting up a query for my inspection test results for a given work piece.

Example Table [Inspection Data]

JOBSERIALPARAMMINMAXVALUEPFDATETIME

11Test101011F6/3/2007

11Test10105P6/4/2007

11Test2286P6/3/2007

11Test2281F6/4/2007

12Test10104P6/3/2007

12Test2285P6/4/2007

11Test3687P6/3/2007

Query table [Inspection Data] for:

JOB = 1

SERIAL = 1

MAX( DATETIME ) for each test

Expected Results:

JOBSERIALPARAMMINMAXVALUEPFDATETIME

11Test10105P6/4/2007

11Test2281F2/4/2007

11Test3687P6/3/2007

Thanks,

Sam

Here you go...

Code Snippet

Create Table #inspectiondata (

[JOB] int ,

[SERIAL] int ,

[PARAM] Varchar(100) ,

[MIN] int ,

[MAX] int ,

[VALUE] int ,

[PF] Varchar(100) ,

[DATETIME] Datetime

);

Insert Into #inspectiondata Values('1','1','Test1','0','10','11','F','6/3/2007');

Insert Into #inspectiondata Values('1','1','Test1','0','10','5','P','6/4/2007');

Insert Into #inspectiondata Values('1','1','Test2','2','8','6','P','6/3/2007');

Insert Into #inspectiondata Values('1','1','Test2','2','8','1','F','6/4/2007');

Insert Into #inspectiondata Values('1','2','Test1','0','10','4','P','6/3/2007');

Insert Into #inspectiondata Values('1','2','Test2','2','8','5','P','6/4/2007');

Insert Into #inspectiondata Values('1','1','Test3','6','8','7','P','6/3/2007');

--For SQL Server 2005

;With CTE

as

(

Select *, Row_Number() OVER(Partition By PARAM Order By [DATETIME] Desc) RowId From #inspectiondata

Where [JOB] = 1 And [SERIAL] = 1

)

Select

[JOB]

,[SERIAL]

,[PARAM]

,[MIN]

,[MAX]

,[VALUE]

,[PF]

,[DATETIME]

From

CTE

Where

RowId = 1

--For SQL Server 2000

Select

Data.[JOB]

,Data.[SERIAL]

,Data.[PARAM]

,Data.[MIN]

,Data.[MAX]

,Data.[VALUE]

,Data.[PF]

,Data.[DATETIME]

From

#inspectiondata Data

Join (

Select

Max([DateTime]) [DateTime]

,PARAM

From

#inspectiondata

Where

[JOB] = 1 And [SERIAL] = 1

Group By

PARAM

) as MaxData On MaxData.[DateTime] = Data.[DateTime] And MaxData.PARAM = Data.PARAM

Where

[JOB] = 1

And [SERIAL] = 1

|||

I was not familiar with CTEs until I read your posting and they seem very easy to read but I cannot get it to compile. The error I get if I name the CTE 'CTE' is 'CTE is not a recognized option'.

Are CTEs available with the Express version of SQL Server?

|||first google result would support this

http://msdn2.microsoft.com/en-us/library/bb264566(SQL.90).aspx

Give the error of why it won't compile.|||

The reason why it was not working is because I had an alter procedure call at the beginning of the stored procedure.

Everything is working perfectly now.

Thank you for your help.

|||

Also, The Alter Procedure call had to be moved to the first line in the sql code.

Thanks again,

Sam

Friday, March 9, 2012

query defining parameter dropdowns is run twice!

I built a very simple report which uses a query to define the options in the parameter’s dropdown. I used that same dataset to define the default for that parameter (meaning that it will just pick the first row from the dataset and use that as the default). When I run the report watching a Profiler trace on the SQL database, it runs that query twice. (Presumably, that’s once to fill the dropdown list and once to figure out the default.) That seems silly to me since it is the same query that is the same dataset in Reporting Services. Is there any way around this? My parameter bar is rendering twice as slowly as it should be.

I've tested against SSRS 2005 SP1 and the CTP of SP2.

Can you confirm your test by removing the default and re-testing to make sure it gets run once. Then adding the default again to confirm it goes back to 2 executions?|||Yes, it only runs it once if I don't specify that the parameter should have a default from a query.

Saturday, February 25, 2012

query builder: how to do a LIKE parameter

hi,

i can do

"select * from products where name = @.name" kind of statements in query builder

but

"select * from products where name LIKE @.name" dosen't work!"


any ideas? i'm using sql server express.

thanks

That statement should look like this:

"select *from productswhere nameLIKE'%' + @.name +'%'"

|||

thanks!! it worked.

just wondering, if i have been using query builder and sql statements to construct tableadapters, would the application be vulnerable to sql injection attacks like classic asp?

|||Yes. Refer toHow To: Protect From SQL Injection in ASP.NET for details.

Query based parameter value changes back to default value

I have several parameters on my report, some have non-queried lists, and
some have queried lists. All of them have default values. When I ran
reports on the Report Manager, I changed the value of the parameters from
the drop-down list to produce different reports. My problem is whenever I
changed the value of a parameter(pA), the value of those queried-based
parameters that were listed after pA would switch back to their respective
default values. This didn't happen when I previewed reports on Visual
Studio .Net Development Environment. Is this a bug, limitation, or am I
missing something?
Any help would be appreciated.
Paul
--
Message posted via http://www.sqlmonster.comPaul,
It sounds like your default values are calculated values (begin with a '=').
The way that RS computes these is that whenever you change a parameter, it
recalculates all the calculated parameters after it. This behaviour is to
allow cascading parameters. As far as I know, there is no way to turn this
calculation off. However, I worked around it by creating another dataset
which had a column for each default value (I do a lot of default dates). You
can then set the default values for the parameters to the dataset value in
the parameters window. I have to use SQL to do the calculations, but for
most things, this should be an easy workaround. It gets rid of the changing
values and also the refresh that takes place when you change calculated
parameters
"Paul via SQLMonster.com" wrote:
> I have several parameters on my report, some have non-queried lists, and
> some have queried lists. All of them have default values. When I ran
> reports on the Report Manager, I changed the value of the parameters from
> the drop-down list to produce different reports. My problem is whenever I
> changed the value of a parameter(pA), the value of those queried-based
> parameters that were listed after pA would switch back to their respective
> default values. This didn't happen when I previewed reports on Visual
> Studio .Net Development Environment. Is this a bug, limitation, or am I
> missing something?
> Any help would be appreciated.
> Paul
> --
> Message posted via http://www.sqlmonster.com
>|||Hi David, that works great. Thank you very much!!
Paul
--
Message posted via http://www.sqlmonster.com

Query based parameter and web service call

has anyone seen this before?
I have a developer that has built a report that has a query based parameter.
Since they want to be able to run the report both interactively and through
a .net batch job. They are attempting to do a soap call to the report
passing a string value in as the query based parameters value. They are
getting a soap exception error .SoapException: Default value or value
provided for the report parameter 'PROD_DESC' is not a valid value. -->
Has anyone seen this before or can verify that you can pass string values
into query based parameters?
Thank YOu!!!We figured out the issue. The developer had a trailing space in his code so
the values in the string were not matching the values returned by the query.
"Mark" wrote:
> has anyone seen this before?
> I have a developer that has built a report that has a query based parameter.
> Since they want to be able to run the report both interactively and through
> a .net batch job. They are attempting to do a soap call to the report
> passing a string value in as the query based parameters value. They are
> getting a soap exception error .SoapException: Default value or value
> provided for the report parameter 'PROD_DESC' is not a valid value. -->
> Has anyone seen this before or can verify that you can pass string values
> into query based parameters?
> Thank YOu!!!