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

Tuesday, March 27, 2012

Configuration files and variables

Hi ..

I need some information on the package configuration files. i.e how to set the configuration parameters from outside the packages. Pls provide me some detailed information along with examples. I want to make my packages to read paramaters from the configuration files as we have in .NET(web.config)////

Secondly I want to know how to play well with variables.. i.e setting a variable.. reading a variable.. passing a variable in the SSIS package dataflows and datatasks.. respectively. Please provide some infomation and a good exam[ple on it I need

sam_idea wrote:

Hi ..

I need some information on the package configuration files. i.e how to set the configuration parameters from outside the packages. Pls provide me some detailed information along with examples. I want to make my packages to read paramaters from the configuration files as we have in .NET(web.config)////

Have you looked in BOL? There's plenty in there regarding SSIS configurations.

Example here: http://www.sqlis.com/?26

sam_idea wrote:

Secondly I want to know how to play well with variables.. i.e setting a variable.. reading a variable.. passing a variable in the SSIS package dataflows and datatasks.. respectively. Please provide some infomation and a good exam[ple on it I need

The 2 most common methods for setting the value of a variable are using an expression (when the variable has EvaluateAsExpression=TRUE, example here: http://blogs.conchango.com/jamiethomson/archive/2005/03/19/1163.aspx) or a script task. There are various tasks (e.g. Execute SQL Task, XML Task) and components (e.g. Rowcount transform, Recordset destination) that can set variable values also.

There is no concept of "passing variables between tasks". A variable is scoped to a container within the package and is accessible by that container and all its ancestral containers. You can pass values between tasks by storing them in variables (note the subtle difference here)

Here's some examples of how you can use variables:

http://blogs.conchango.com/jamiethomson/archive/2005/07/04/1748.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/04/09/1265.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/06/15/1693.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/05/30/1489.aspx

http://blogs.conchango.com/jamiethomson/archive/2005/02/09/964.aspx

Here's a tip for you. Google is your friend and alot quicker than this forum: http://www.google.co.uk/search?hl=en&q=ssis+configurations&meta=

-Jamie

Thursday, March 22, 2012

Conditionally showing/hiding a parameter

I have a report that in most cases takes 4 parameters. In a few special cases, though, it takes 5 parameters. I have my code modified enough such that it can handle this exception, however I cannot figure out how to conditionally show the 5th parameter based on the 4th parameter. Is this possible?

how to conditionally show the 5th parameter based on the 4th parameter. Is this possible?

Yes, this is possible. Lets say your 5th parameter is driven off of a query, then you can pass what ever is selected in the 4th parameter as an input to the query. Also in the report parameter your 5th parameter should be below the 4th parameter meaning the order of the parameters is important.

Let me know if you would want me to elaborate this further.

|||

You're describing how to change the available values of the 5th parameter based on the choice made for the 4th parameter. I think the original question is it possible to show or hide the 5th parameter based on the choice made for the 4th parameter.

I have never found a way to conditionally hide parameters and don't believe it's possible. If I'm wrong then I'd love to hear how to do it. When we've encountered cases like this we've had to just change the values of the 5th parameter (as Techquest has described) to have only a single item available such as "n/a" and then defaulted to that value.

I'd also love to hear if there's a way to conditionally change the label for parameters. I don't believe this is possible either but there's a lot of smart people out there and it would be great if someone could show me that I'm wrong.

tia

-bruce

|||Bruce, that's what I wanted to do.

I haven't been working with SSRS for too long, I wonder if it's possible to write a script or extension to allow more flexibility in the parameters.

I like the N/A idea though, that'll work if I can't figure out anything new.

Thanks,

Erik

Sunday, March 11, 2012

Conditional Selection

Hi,
Hi,
I'm trying to construct a query (in a stored procedure) which will have a nu
mber of
selection criteria based on input parameters. There are a number of these p
arameters
whose selection conditions they represent which all have to be true for a ro
w to be
returned in the resultset.
The basic query is:
SELECT Store, StoreNumber
FROM Stores
WHERE ...
I'm trying to come up with the WHERE clause.
For example, I want to define a parameter named @.ExcludeSpecialties which if
it has
the value 1, means to return all stores but exclude stores whose StoreNumber
is in
the list (800, 802, 804). If the parameter has the value 0, then it means "
don't
care" and all StoreNumbers should be returned.
One could certainly argue that there probably should have been an column in
the
Stores row to indicate the store is a specialty store, rather than using a h
ard-wired
list of numbers. But the current data schema cannot be easily changed. Bes
ides, the
list never changes.
Indeed, there is a Franchise bit column in the row which is selected by anot
her
parameter called @.ExcludeFranchise whose WHERE predicate could be written as
:
WHERE Franchise = CASE WHEN @.ExcludeFranchise = 1 THEN 0 ELSE Franchise END
and if all the parameters were like this, I wouldn't be posting. Sadly, for
the
Specialties test I'm stuck with a NOT IN list.
This is easy enough to do in an IF/ELSE block, but there are several such si
milar
parameters whose values may be specified in any combination. This, I think,
makes
IF/ELSE impractical as the number of IF/ELSE statements to handle all possib
le
combinations would grow very quickly.
I'm hoping there is a simple solution to this NOT IN list, and it's just tha
t I can't
see it.
Can anyone help?
Thanks,
-- JeffTry this first ( Several popular approaches are details here ):
http://www.sommarskog.se/dyn-search.html
Anith|||try this in your where clause. Let me know if this helps
((@.ExcludeSpecialties = 0) or (storenumber not in (800, 802, 804)))|||You could store the specialties flag in a seperate table, with StoreNumber
as the key, then query against it instead of using the hardcoded list. This
way, when a new specialty store opens, or one of the existing stores
changes, you will just insert a row into the table and not have to touch the
code. It would be better to have it in the original table, but if you can't
change the original, maybe adding a new table is an option...
create table SpecialtyStores
(StoreNumber integer, Specialty bit) -- add PK and FK info here
SELECT Store, StoreNumber
FROM Stores
left outer join SpecialtyStores as spec
on stores.StoreNumber = spec.StoreNumber
WHERE
Specialty = CASE WHEN @.ExcludeFranchise = 1 THEN 0 ELSE 1 END
"Jeff Mason" <je.mason@.comcast.net> wrote in message
news:vvl1525lk0m8baqqpv5vs5q1g36a9c6jpa@.
4ax.com...
> Hi,
> Hi,
> I'm trying to construct a query (in a stored procedure) which will have a
number of
> selection criteria based on input parameters. There are a number of these
parameters
> whose selection conditions they represent which all have to be true for a
row to be
> returned in the resultset.
> The basic query is:
> SELECT Store, StoreNumber
> FROM Stores
> WHERE ...
> I'm trying to come up with the WHERE clause.
> For example, I want to define a parameter named @.ExcludeSpecialties which
if it has
> the value 1, means to return all stores but exclude stores whose
StoreNumber is in
> the list (800, 802, 804). If the parameter has the value 0, then it means
"don't
> care" and all StoreNumbers should be returned.
> One could certainly argue that there probably should have been an column
in the
> Stores row to indicate the store is a specialty store, rather than using a
hard-wired
> list of numbers. But the current data schema cannot be easily changed.
Besides, the
> list never changes.
> Indeed, there is a Franchise bit column in the row which is selected by
another
> parameter called @.ExcludeFranchise whose WHERE predicate could be written
as:
> WHERE Franchise = CASE WHEN @.ExcludeFranchise = 1 THEN 0 ELSE Franchise
END
> and if all the parameters were like this, I wouldn't be posting. Sadly,
for the
> Specialties test I'm stuck with a NOT IN list.
> This is easy enough to do in an IF/ELSE block, but there are several such
similar
> parameters whose values may be specified in any combination. This, I
think, makes
> IF/ELSE impractical as the number of IF/ELSE statements to handle all
possible
> combinations would grow very quickly.
> I'm hoping there is a simple solution to this NOT IN list, and it's just
that I can't
> see it.
> Can anyone help?
> Thanks,
> -- Jeff|||On Thu, 27 Apr 2006 08:13:02 -0700, Omnibuzz <Omnibuzz@.discussions.microsoft
.com>
wrote:

>try this in your where clause. Let me know if this helps
>((@.ExcludeSpecialties = 0) or (storenumber not in (800, 802, 804)))
Duh.
That did it. I knew it was something simple. I was having a Brain Fog, I gu
ess.
Thank you.
-- Jeff

Conditional Report Parameters

I have a report with required parameters of company and project. I then have 3 parameters that I want to be conditional - start date, end date and cycle.

By conditional I mean if cycle is chosen then start & end date are not required. If start and end date are chosen then cycle is not required.

I have made all 3 parameters 'Allow Null Values" however cycle's available values are set from a query once a project is chosen. When the field refreshes I lose my null checkbox for cycle, so it ends up always being required.

Am I going about this the wrong way? I'm using 2005.

I'm not sure that conditional report parameters exist, but could you accomplish this using optional parameters?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=621340&SiteID=1

|||

Hmm, not really. I don't want all 3 to be optional, either cycle or start/end date need to be required.

I'll keep banging my head against the wall... Thanks though.

Conditional Query

Hi,

I'm trying to construct a query (in a stored procedure) which will have a number of
selection criteria based on input parameters. There are a number of these parameters
whose selection conditions they represent which all have to be true for a row to be
returned in the resultset.

The basic query is:

SELECT Store, StoreNumber
FROM Stores
WHERE ...

I'm trying to come up with the WHERE clause.

For example, I want to define a parameter named @.ExcludeSpecialties which if it has
the value 1, means to return all stores but exclude stores whose StoreNumber is in
the list (800, 802, 804). If the parameter has the value 0, then it means "don't
care" and all StoreNumbers should be returned.

One could certainly argue that there probably should have been an column in the
Stores row to indicate the store is a specialty store, rather than using a hard-wired
list of numbers. But the current data schema cannot be easily changed. Besides, the
list never changes.

Indeed, there is a Franchise bit column in the row which is selected by another
parameter called @.ExcludeFranchise whose WHERE predicate could be written as:

WHERE Franchise = CASE WHEN @.ExcludeFranchise = 1 THEN 0 ELSE Franchise END

and if all the parameters were like this, I wouldn't be posting. Sadly, for the
Specialties test I'm stuck with a NOT IN list.

This is easy enough to do in an IF/ELSE block, but there are several such similar
parameters whose values may be specified in any combination. This, I think, makes
IF/ELSE impractical as the number of IF/ELSE statements to handle all possible
combinations would grow very quickly.

I'm hoping there is a simple solution to this NOT IN list, and it's just that I can't
see it.

Can anyone help?

Thanks,

-- JeffJeff Mason (je.mason@.comcast.net) writes:
> I'm trying to construct a query (in a stored procedure) which will have
> a number of selection criteria based on input parameters. There are a
> number of these parameters whose selection conditions they represent
> which all have to be true for a row to be returned in the resultset.

I have an article on by web site that discusses a couple of alternatives,
both with static and dynamic SQL:
http://www.sommarskog.se/dyn-search.html

--
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|||On Thu, 27 Apr 2006 11:10:01 -0400, Jeff Mason wrote:

(snip)
>For example, I want to define a parameter named @.ExcludeSpecialties which if it has
>the value 1, means to return all stores but exclude stores whose StoreNumber is in
>the list (800, 802, 804). If the parameter has the value 0, then it means "don't
>care" and all StoreNumbers should be returned.

Hi Jeff,

WHERE ( @.ExcludeSpecialties = 0 OR StoreNumber NOT IN (800, 802, 804) )

(snip)
>Indeed, there is a Franchise bit column in the row which is selected by another
>parameter called @.ExcludeFranchise whose WHERE predicate could be written as:
>WHERE Franchise = CASE WHEN @.ExcludeFranchise = 1 THEN 0 ELSE Franchise END
>and if all the parameters were like this, I wouldn't be posting. Sadly, for the
>Specialties test I'm stuck with a NOT IN list.

That is indeed a common method to write such queries.

Do read the article Erland posted a link to - it describes a bunch of
methods to achieve what you need, with all their strengths and
weaknesses. Good stuff!

--
Hugo Kornelis, SQL Server MVP

Thursday, March 8, 2012

Conditional Parameters

Hi all
I cant get my head round conditional parameters. I have a report with two
parameters and I would like the user to be able to select either one or both
of the parameters.
IE.
Param 1 Firstname
Param 2 Lastname
The user should be able to enter into the first parameter, or the second
parameter or both. How do I acheive this and construct the SQL accordingly.
Thanks
Dave.David,
I used similar code in one of my reports:
where FirstName like (case when IsNull(@.FName, '') = '' then '%' else '%' +
@.FName end)
and LastName like (case when IsNull(@.LName, '') = '' then '%' else '%' +
@.LName end)
HTH,
Andrei.
"David Hines" <DavidHines@.discussions.microsoft.com> wrote in message
news:249315AC-DE87-4AF6-8013-025A9CA4EA81@.microsoft.com...
> Hi all
> I cant get my head round conditional parameters. I have a report with two
> parameters and I would like the user to be able to select either one or
both
> of the parameters.
> IE.
> Param 1 Firstname
> Param 2 Lastname
> The user should be able to enter into the first parameter, or the second
> parameter or both. How do I acheive this and construct the SQL
accordingly.
> Thanks
> Dave.|||Hi Andrei
You pointed me in just the right direction Thankyou.
Finished SQL was
WHERE (FirstName LIKE '%' + (CASE WHEN IsNull(@.Fname, '') = '' THEN '%'
ELSE @.Fname END) + '%') AND (LastName LIKE '%' + (CASE WHEN IsNull(@.LName,
'') = '' THEN '%' ELSE + @.Lname END) + '%') AND (LEN(@.Lname) +
LEN(@.OwnerCode) > 0)
Again Many Thanks for your speedy response.
Dave.
"andrei" wrote:
> David,
> I used similar code in one of my reports:
> where FirstName like (case when IsNull(@.FName, '') = '' then '%' else '%' +
> @.FName end)
> and LastName like (case when IsNull(@.LName, '') = '' then '%' else '%' +
> @.LName end)
> HTH,
> Andrei.
>
> "David Hines" <DavidHines@.discussions.microsoft.com> wrote in message
> news:249315AC-DE87-4AF6-8013-025A9CA4EA81@.microsoft.com...
> > Hi all
> > I cant get my head round conditional parameters. I have a report with two
> > parameters and I would like the user to be able to select either one or
> both
> > of the parameters.
> >
> > IE.
> >
> > Param 1 Firstname
> > Param 2 Lastname
> >
> > The user should be able to enter into the first parameter, or the second
> > parameter or both. How do I acheive this and construct the SQL
> accordingly.
> >
> > Thanks
> >
> > Dave.
>
>|||Another solution - I just don't like using LIKE...
--
WHERE (FirstName = @.Fname OR @.Fname IS NULL)
AND (LastName = @.Lname OR @.Lname IS NULL)
AND ...
--
This works very well when you have "<ALL>" as an option for a parameter.
Fred
"David Hines" wrote:
> Hi Andrei
> You pointed me in just the right direction Thankyou.
> Finished SQL was
> WHERE (FirstName LIKE '%' + (CASE WHEN IsNull(@.Fname, '') = '' THEN '%'
> ELSE @.Fname END) + '%') AND (LastName LIKE '%' + (CASE WHEN IsNull(@.LName,
> '') = '' THEN '%' ELSE + @.Lname END) + '%') AND (LEN(@.Lname) +
> LEN(@.OwnerCode) > 0)
> Again Many Thanks for your speedy response.
> Dave.
>
> "andrei" wrote:
> > David,
> >
> > I used similar code in one of my reports:
> >
> > where FirstName like (case when IsNull(@.FName, '') = '' then '%' else '%' +
> > @.FName end)
> > and LastName like (case when IsNull(@.LName, '') = '' then '%' else '%' +
> > @.LName end)
> >
> > HTH,
> > Andrei.
> >
> >
> > "David Hines" <DavidHines@.discussions.microsoft.com> wrote in message
> > news:249315AC-DE87-4AF6-8013-025A9CA4EA81@.microsoft.com...
> > > Hi all
> > > I cant get my head round conditional parameters. I have a report with two
> > > parameters and I would like the user to be able to select either one or
> > both
> > > of the parameters.
> > >
> > > IE.
> > >
> > > Param 1 Firstname
> > > Param 2 Lastname
> > >
> > > The user should be able to enter into the first parameter, or the second
> > > parameter or both. How do I acheive this and construct the SQL
> > accordingly.
> > >
> > > Thanks
> > >
> > > Dave.
> >
> >
> >

Conditional Parameters

Does anyone know if there is a way to have conditional parameters? Ex: User
asked would you like to run report by representative or area? Then when the
user chose representative a mulit select prompt would appear with a list of
representatives to choose from or if they chose area then a multi selection
of areas to choose from would appear.Hi Kim,
Yes it can be done. From your post, you need to create 3 dataset.
1. Which gives you Rep.. or Area
2. Which gives you the list of rep for selection (multi selection)
3. Once you select it displayes the result.
On 2 & 3 data option give an if condition accordingly
e.g
If @.rep = 1
select * from rep
else
select * from Area
Any doubts, Let me know.
Amarnath
"KimB" wrote:
> Does anyone know if there is a way to have conditional parameters? Ex: User
> asked would you like to run report by representative or area? Then when the
> user chose representative a mulit select prompt would appear with a list of
> representatives to choose from or if they chose area then a multi selection
> of areas to choose from would appear.|||Thank you! I will try that.
"Amarnath" wrote:
> Hi Kim,
> Yes it can be done. From your post, you need to create 3 dataset.
> 1. Which gives you Rep.. or Area
> 2. Which gives you the list of rep for selection (multi selection)
> 3. Once you select it displayes the result.
> On 2 & 3 data option give an if condition accordingly
> e.g
> If @.rep = 1
> select * from rep
> else
> select * from Area
> Any doubts, Let me know.
> Amarnath
>
> "KimB" wrote:
> > Does anyone know if there is a way to have conditional parameters? Ex: User
> > asked would you like to run report by representative or area? Then when the
> > user chose representative a mulit select prompt would appear with a list of
> > representatives to choose from or if they chose area then a multi selection
> > of areas to choose from would appear.

Conditional parameters

I have two parameters, one list box generated from a union dataset, that has
an option to generate the report for all suppliers. When this option is
selected the second parameter (a search parameter, based on user input) must
not allow the input of %, can anyone let me know how this can be achieved.
Also can a error message be displayed when the user inputs a %?
Any help greatly anticipated.
Dave.I assume that you are generating reports directly from the
report manager.
I dont know if there is a direct way of acchieving this
but would like to suggest a work around.
Have an additional text box and type in some error text in
it eg : "Please do not enter %" or "Wrong parameters"
Then set the hidden property of this text box to an
expression that validates the parameter value and hides
the textbox if the values entered are correct otherwise
the textbox is visible.
Then for other controls on the report set the same
condition for visibility but in this case make the
controls visible if the parameters entered are correct
otherwise the controls will be hidden.
So if the user enters a wrong value for the second
parameter then only one textbox will appear asking the
user to enter the values again.
Hope this helps!
>--Original Message--
>I have two parameters, one list box generated from a
union dataset, that has
>an option to generate the report for all suppliers. When
this option is
>selected the second parameter (a search parameter, based
on user input) must
>not allow the input of %, can anyone let me know how this
can be achieved.
>Also can a error message be displayed when the user
inputs a %?
>Any help greatly anticipated.
>Dave.
>.
>

Conditional input params to SP

I've got a pretty straightforward search/results suite with several possible search parameters on the search page. I've been using an inline SQL server query with logic on the results page as shown below. How do I convert this kind of conditional logic to a stored procedure?

Dim strWhere
strWhere = " WHERE dbo.""User"".UID IS NOT NULL "

If Not request.querystring("EmployerID") = "" Then
strWhere = strWhere & " AND dbo.""User"".EmployerID = '" & replace(request.querystring("EmployerID"),"'","''") & "'"
End If

If Not request.querystring("AccountNumber") = "" Then
strWhere = strWhere & " AND dbo.""User"".AccountNumber = '" & replace(request.querystring("AccountNumber"),"'","''") & "'"
End If

If Not request.querystring("LastName") = "" Then
strWhere = strWhere & " AND dbo.""User"".LastName = '" & replace(request.querystring("LastName"),"'","''") & "'"
End If

If Not request.querystring("FirstName") = "" Then
strWhere = strWhere & " AND dbo.""User"".FirstName = '" & replace(request.querystring("FirstName"),"'","''") & "'"
End If

DBConn = New OleDbConnection(ConfigurationSettings.AppSettings("ConnStr"))
DBCommand = New OleDbDataAdapter _
("SELECT dbo.""User"".*, Convert(varchar(16), dbo.""User"".DateEntered, 101) AS Created, dbo.Employer.CompanyName, dbo.AccessLevel.AccessLevel AS AccessLevelName FROM dbo.""User"" INNER Join dbo.Employer ON dbo.""User"".EmployerID = dbo.Employer.EmployerID INNER JOIN dbo.AccessLevel ON dbo.""User"".AccessLevel = dbo.AccessLevel.AccessLevelID " & strWhere & " ORDER BY " & strSortField,DBConn)

Thanks in advance?Here is a pretty complete, though somewhat dated, overview on doing what you are looking to do (in this case inside a stored procedure, but you could do the same with a parameterized query, I expect).

What you are doing is succeptable to SQL Injection attacks, and a number of other potential problems...|||Thanks much. Great article, just what I was looking for.

I'll be coding with SQL Injection in mind as well...|||example of how i go about optional inputs

create procedure myprocedure
@.field1 type = null,
@.field2 type = null,
@.field3 type = null

as

select * from mytable where field1 = isnull(@.field1, field1)
and field2 = isnull(@.field2, field2)
and field3 = isnull(@.field3, field3)

this could be taxing on a table with a lot of entries, but for small tables this works out well and keeps me from having to write multiple sprocs for different parms

Wednesday, March 7, 2012

Conditional Formating of axis labels(Urgent!)

Depending on the time interval, that is covered by the report and which will
be provided by parameters, the format of the x-axis labels should be e.g.
hh:mm:ss or dd.mm.yyyy. It seems to me, that the format can only be defined
statically. Why can't I use expressions here?
Any help is appreciated, thanks.You can certainly use expressions for the format code on x-axis labels.
However, make sure that the category grouping expressions (which get applied
to the x-axis) result in objects of type DateTime and not in strings. Format
codes won't have any effect on strings.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Niklas" <Niklas@.discussions.microsoft.com> wrote in message
news:FD03A48E-AA5C-400E-815D-FDE48CD07CD0@.microsoft.com...
> Depending on the time interval, that is covered by the report and which
will
> be provided by parameters, the format of the x-axis labels should be e.g.
> hh:mm:ss or dd.mm.yyyy. It seems to me, that the format can only be
defined
> statically. Why can't I use expressions here?
> Any help is appreciated, thanks.

Friday, February 24, 2012

Conditional Cascading Parameters

Hi,
I am looking for some help with builing parameters in a report. A have a
report that displays sales persons. What I need to do is either allow entry
of the sales person number directly OR use a set of cascading parameters that
start at country, then region, then state, followed by office. The office
parameter/query would display all salespersons for that office.
Is there any way that when the salesperson number is entered directly to
disable all other parameters and render the report? On the flip side, if the
salesperson number is not entered, then allow all other parameters.
Thank you,
BobI am not aware of a way to do this, although I have messed with it a
little... It would be a nice feature to have, but right now I think you'd
have to do this in HTML in front of the report
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:DFACCE39-01A3-495F-BBD1-0013A6CA1D62@.microsoft.com...
> Hi,
> I am looking for some help with builing parameters in a report. A have a
> report that displays sales persons. What I need to do is either allow
> entry
> of the sales person number directly OR use a set of cascading parameters
> that
> start at country, then region, then state, followed by office. The office
> parameter/query would display all salespersons for that office.
> Is there any way that when the salesperson number is entered directly to
> disable all other parameters and render the report? On the flip side, if
> the
> salesperson number is not entered, then allow all other parameters.
> Thank you,
> Bob|||I thought I may need to put a front end on the report. Thank you for
comfirming this.
Bob
"Wayne Snyder" wrote:
> I am not aware of a way to do this, although I have messed with it a
> little... It would be a nice feature to have, but right now I think you'd
> have to do this in HTML in front of the report
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Bob" <Bob@.discussions.microsoft.com> wrote in message
> news:DFACCE39-01A3-495F-BBD1-0013A6CA1D62@.microsoft.com...
> > Hi,
> >
> > I am looking for some help with builing parameters in a report. A have a
> > report that displays sales persons. What I need to do is either allow
> > entry
> > of the sales person number directly OR use a set of cascading parameters
> > that
> > start at country, then region, then state, followed by office. The office
> > parameter/query would display all salespersons for that office.
> >
> > Is there any way that when the salesperson number is entered directly to
> > disable all other parameters and render the report? On the flip side, if
> > the
> > salesperson number is not entered, then allow all other parameters.
> >
> > Thank you,
> >
> > Bob
>
>

Friday, February 10, 2012

concatenating sql fields and parameters

Hi,
I am trying to run a update stored procedure where one of the fields is
dynamic eg.
UPDATE table
SET field_ + @.number = @.a_value
WHERE (key = @.key_value)
@.number is chosen by the user and the field_## can be anything from field_01
to field_99.
Is there a way i can do this? The above method doesn’t work.
Any help will be greatly appreciated.
Many ThanksIn t-SQL, you will have to use each columns explcitly in the SET clause,
with commas separating each column assignments. For syntax, refer to the
topic UPDATE in SQL Server Books Online.
Perhaps with Dynamic SQL you might be able to kludge it out. For details,
refer to EXEC & sp_ExecuteSQL in SQL Server Books Online. On a side note, it
is possible that you have a flawed design which force you to use such
meaningless constructs in your code.
Anith|||Hi Vortex
consider rewriting as:
EXECUTE('UPDATE table SET field_' + @.number + ' = ' +@.a_value + ' WHERE
key = ' + @.key_value)
best Regards,
Chandra
http://chanduas.blogspot.com/
---
"vortex" wrote:

> Hi,
> I am trying to run a update stored procedure where one of the fields is
> dynamic eg.
> UPDATE table
> SET field_ + @.number = @.a_value
> WHERE (key = @.key_value)
> @.number is chosen by the user and the field_## can be anything from field_
01
> to field_99.
> Is there a way i can do this? The above method doesn’t work.
> Any help will be greatly appreciated.
> Many Thanks
>|||I will give it a try,
I am creating a stored procedure with your update command, if I use the
method you suggested will SQL have to compile the sp every time a new value
is used or will it just compile the once. (Speed is required, that is why I
am using a sp)
Thanks
Khalid
"Chandra" wrote:
> Hi Vortex
> consider rewriting as:
> EXECUTE('UPDATE table SET field_' + @.number + ' = ' +@.a_value + ' WHERE
> key = ' + @.key_value)
>
> --
> best Regards,
> Chandra
> http://chanduas.blogspot.com/
> ---
>
> "vortex" wrote:
>|||If you can suggest a better way of doing it, i would be a very happy bunny a
s
i have a lot more stored procedures to write :(
thanks
"Anith Sen" wrote:

> In t-SQL, you will have to use each columns explcitly in the SET clause,
> with commas separating each column assignments. For syntax, refer to the
> topic UPDATE in SQL Server Books Online.
>
> Perhaps with Dynamic SQL you might be able to kludge it out. For details,
> refer to EXEC & sp_ExecuteSQL in SQL Server Books Online. On a side note,
it
> is possible that you have a flawed design which force you to use such
> meaningless constructs in your code.
> --
> Anith
>
>|||It is not as ease as it seems. For example, Chandra's solution will fail if
@.number is tinyint/int/bigint because you can not those data types have
greater precedence than varchar so sql server will try to convert 'UPDATE
table SET field_' to tinyint/int/bigint and this will give an error. The sam
e
will happen @.a_value, you have to quote it between apostrophes for char /
varchar / datetime values. The same with @.key_value. You will have to use
dynamic sql and bunch on lines to accomodate the statement to the variables
data type.
I will not write about readability and maintenance of your final code, you
can guess what will be the result.
The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html
AMB
"vortex" wrote:

> I will give it a try,
> I am creating a stored procedure with your update command, if I use the
> method you suggested will SQL have to compile the sp every time a new valu
e
> is used or will it just compile the once. (Speed is required, that is why
I
> am using a sp)
> Thanks
> Khalid
> "Chandra" wrote:
>
>|||>> If you can suggest a better way of doing it,..
Better way of doing an UPDATE or changing the design? Regarding the UPDATE,
did you refer to the manual for exact syntax?
Regarding the design, with simple one-liners as in your initial post, it is
hard to suggest anything meaningful. Post some more information regarding
this table, the entity type that is being modelled and the attributes
involved. Also provide some details regarding the business model and how
this table fits into the overall schema.
Generally it is hard to provide accurate design suggestions over newsgroup
responses, however with the above requested info, you could perhaps get
started.
Anith

Concatenating output parameters

I have a stored procedure (PROC1) that calls another stored procedure (PROC2
)
multiple times. Both procedures have an output parameter and I am wondering
if I can take the multiple output parameters from PROC2 and combine them int
o
the parameter that is output for PROC1. Example...
Say that PROC2 is called 4 times and the output from each call is this
1
2
3
4
I want the output of PROC1 to be 1234. Any help is appreciated.
ThanksYes, create a varchar() column, of appropriate size, and each time you call
the stored proc (Proc2) append the return value to the VarChar variable
Now, the output of the stored proc can be in an output parameter, or just
the return value... WHich is it? If it's an Output parameter
Declare @.Var VarChar(10)
Set @.Var = '' -- Set as empty string to avoid Null propagation issues
Exec PROC2 ..., <@.OutputParam OUTPUT, ...
Select @.Var = @.Var + @.OutputParam
-- ---
Exec PROC2 ..., <@.OutputParam OUTPUT, ...
Select @.Var = @.Var + @.OutputParam
-- ---
Exec PROC2 ..., <@.OutputParam OUTPUT, ...
Select @.Var = @.Var + @.OutputParam
-- ---
Exec PROC2 ..., <@.OutputParam OUTPUT, ...
Select @.Var = @.Var + @.OutputParam
-- ---
"Andy" wrote:

> I have a stored procedure (PROC1) that calls another stored procedure (PRO
C2)
> multiple times. Both procedures have an output parameter and I am wonderi
ng
> if I can take the multiple output parameters from PROC2 and combine them i
nto
> the parameter that is output for PROC1. Example...
> Say that PROC2 is called 4 times and the output from each call is this
> 1
> 2
> 3
> 4
> I want the output of PROC1 to be 1234. Any help is appreciated.
> Thanks|||Example:
use northwind
go
create procedure proc1
@.p1 int output
as
set nocount on
set @.p1 = (select top 1 orderid from dbo.orders order by newid())
return @.@.error
go
create procedure proc2
@.p1 varchar(128) output
as
set nocount on
declare @.i int
declare @.j int
declare @.s varchar(128)
set @.i = 1
set @.s = ''
while @.i <= 4
begin
set @.j = null
exec proc1 @.J output
if @.j is not null
set @.s = @.s + case when @.s > '' then '|' else '' end + ltrim(@.j)
set @.i = @.i + 1
end
set @.p1 = @.s
return 0
go
declare @.s varchar(128)
exec proc2 @.s output
print @.s
go
drop procedure proc2, proc1
go
AMB
"Andy" wrote:

> I have a stored procedure (PROC1) that calls another stored procedure (PRO
C2)
> multiple times. Both procedures have an output parameter and I am wonderi
ng
> if I can take the multiple output parameters from PROC2 and combine them i
nto
> the parameter that is output for PROC1. Example...
> Say that PROC2 is called 4 times and the output from each call is this
> 1
> 2
> 3
> 4
> I want the output of PROC1 to be 1234. Any help is appreciated.
> Thanks|||Thanks a lot for your help on this. I should have mentioned that I am using
dynamic SQL. Here is a sample of my code. I have declared all of the
variables in my code and am trying to have @.p as my output. I know you
cannot use Set in dynamic SQL but am hoping I have other options.
@.BottomLimit and @.TopLimit are .5
@.TableName is the name of the table
@.PreviousLoad and @.CurrentLoad are passed in as '200408' and '200409'
The tables I am looking at are partitioned and I am comparing last month's
row count to this month's. Just to give you a better idea of the code below
.
Set @.SQL = 'Set @.p = (Select Case When(((SELECT Count(*) FROM ' + @.TableName
+ @.CurrentLoad + ' ) Between
( SELECT Count(*) - Count(*) * ' + @.BottomLimit + ' FROM ' + @.TableName +
@.PreviousLoad + ' ) AND
( SELECT Count(*) + Count(*) * ' + @.TopLimit + ' FROM ' + @.TableName +
@.PreviousLoad + ' )))
THEN ''QC has passed for ' + @.TableName + @.CurrentLoad + '''
ELSE ''QC has failed for ' + @.TableName + @.CurrentLoad + '''END)'
exec(@.SQL)
Any help you can provide is greatly appreciated!!!!!
"Alejandro Mesa" wrote:
> Example:
> use northwind
> go
>
> create procedure proc1
> @.p1 int output
> as
> set nocount on
> set @.p1 = (select top 1 orderid from dbo.orders order by newid())
> return @.@.error
> go
> create procedure proc2
> @.p1 varchar(128) output
> as
> set nocount on
> declare @.i int
> declare @.j int
> declare @.s varchar(128)
> set @.i = 1
> set @.s = ''
> while @.i <= 4
> begin
> set @.j = null
> exec proc1 @.J output
> if @.j is not null
> set @.s = @.s + case when @.s > '' then '|' else '' end + ltrim(@.j)
> set @.i = @.i + 1
> end
> set @.p1 = @.s
> return 0
> go
> declare @.s varchar(128)
> exec proc2 @.s output
> print @.s
> go
> drop procedure proc2, proc1
> go
>
> AMB
>
> "Andy" wrote:
>|||andy,
if you absolutely have to use dynamic SQL, then you need to switch from
using "EXEC" to using a built-in System stored proc called sp_ExecuteSQL()
... Look it upo in the Books On LIne.
When you use EXEC, the called stored proc runs in it's own context, and the
value of Output parameters is not available to the caller stored proc. If
you use so_ExecuteSQL, then toy CAN define an output Parameter in the Caller
SP whose value will be modified by the Called SP, and will later be avaliabl
e
back in the caller after the SP runs...
"Andy" wrote:
> Thanks a lot for your help on this. I should have mentioned that I am usi
ng
> dynamic SQL. Here is a sample of my code. I have declared all of the
> variables in my code and am trying to have @.p as my output. I know you
> cannot use Set in dynamic SQL but am hoping I have other options.
> @.BottomLimit and @.TopLimit are .5
> @.TableName is the name of the table
> @.PreviousLoad and @.CurrentLoad are passed in as '200408' and '200409'
> The tables I am looking at are partitioned and I am comparing last month's
> row count to this month's. Just to give you a better idea of the code bel
ow.
> Set @.SQL = 'Set @.p = (Select Case When(((SELECT Count(*) FROM ' + @.TableNa
me
> + @.CurrentLoad + ' ) Between
> ( SELECT Count(*) - Count(*) * ' + @.BottomLimit + ' FROM ' + @.TableName
+
> @.PreviousLoad + ' ) AND
> ( SELECT Count(*) + Count(*) * ' + @.TopLimit + ' FROM ' + @.TableName +
> @.PreviousLoad + ' )))
> THEN ''QC has passed for ' + @.TableName + @.CurrentLoad + '''
> ELSE ''QC has failed for ' + @.TableName + @.CurrentLoad + '''END)'
> exec(@.SQL)
>
> Any help you can provide is greatly appreciated!!!!!
> "Alejandro Mesa" wrote:
>