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

Wednesday, March 28, 2012

How to assign string value to TEXT output parameter of a stored procedure?

Hello,

I am currently trying to assign some string to a TEXT output parameter
of a stored procedure.

The basic structure of the stored procedure looks like this:

-- 8< --
CREATE PROCEDURE owner.StoredProc
(
@.blob_data image,
@.clob_data text OUTPUT
)
AS
INSERT INTO Table (blob_data, clob_data) VALUES \
(@.blob_data, @.clob_data);
GO
-- 8< --

My previous attempts include using the convert function to convert a
string into a TEXT data type:
SET @.clob_data = CONVERT(text, 'This is a test');

Unfortunately, this leads to the following error: "Error 409: The
assignment operator operation cannot take a text data type as an argument."

Is there any alternative available to make an assignment to a TEXT
output parameter?

Regards,
ThiloIs there a reason you can't just do a select on it?

How to assign different identity ranges to publisher and subscribers?

Hello,
There is a @.identity_range parameter, which controls the identity
range size initially allocated both to the publisher and to
subscribers in sql server 2005 merge replication. I need to assign
different identity ranges for publisher and subscribers. Is it
possible to achieve it? The @.pub_identity_range parameter does not
seem to work.
Thanks you,
Jawad
You can do it manually using checkident or using the create publication
wizard (see the article properties dialog, its in the identity range
management section).
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"JDee" <jawwad.ali@.gmail.com> wrote in message
news:1174476685.219315.29270@.n59g2000hsh.googlegro ups.com...
> Hello,
> There is a @.identity_range parameter, which controls the identity
> range size initially allocated both to the publisher and to
> subscribers in sql server 2005 merge replication. I need to assign
> different identity ranges for publisher and subscribers. Is it
> possible to achieve it? The @.pub_identity_range parameter does not
> seem to work.
> Thanks you,
> Jawad
>

How to assign a value to a parameter?

Hello everyone,

i have the parameter in my stored procedure that i am using as a sqldatasource.

Now in one of the events, i need to assign a value to the parameter. How can i do that?

Microsoft is changing the syntax so often, all solutions i found on this forum just don't work anymore, like:

SqlDataSource1.SelectParameters[

"@.CompareInteger"].value="1"

OR

SqlDataSource1.SelectParameters["@.CompareInteger"].DefaultValue="1"

I guess the SelectParameter - became 'ReadOnly'..But how to assign value to a parameter now?!?

Thanks for any help

They aren't changing the syntax.. Hasn't ever changed, but those methods you mentioned above only work in certain circumstances, because they are "hacks".

What you want to do is capture the SqlDataSource1_Selecting event. From within that event, you have access to the underlying command (and parameters collection). Your code from within that event would looks something like:

e.Parameters["@.CompareInteger"].Value="1;

Or

e.parameters("@.compareinteger").value="1" if you are using VB.NET

|||

it does not work, Motley. It does not work.

for SqlDataSource1_Selecting event, e does not have such an option - e.parameters - check it for yourself...:(

So, the question still remains - HOW TO ASSIGN VALUE TO A PARAMETER?

|||IS there any way to assign the value to a parameter?!?!? in any event procedure?|||

If it's not e.parameters, then it's one of the following:

e.SelectCommand.Parameters

or

e.Command.Parameters

|||

thank you, Motley ! Will remember it now.

Wednesday, March 21, 2012

How to allow apostrophes in string parameters

I have a few reports that contain a customer name parameter. I have
just realized that when a customer name contains a single-quote
(apostrophe), reporting services thinks that it's an unclosed string
and I receive an error.
The error I get -
"An error has occurred during report processing.
Query execution failed for data set '....'.
Line 1: Incorrect syntax near 's'.
Unclosed quotation mark before the character string"."
I know that I probably need to 'escape' the single quote, but I am
unclear if I can do this on the data tab in report designer or if I
have to do this through my views/stored procs in sql server. After
determining where to make the change, I will also need to know what
the correct syntax is.
Thanks so much for your help.
CrystalOn Feb 14, 11:59=A0am, Just Another Reporter <Crystal.War...@.gmail.com>
wrote:
> I have a few reports that contain a customer name parameter. =A0I have
> just realized that when a customer name contains a single-quote
> (apostrophe), reporting services thinks that it's an unclosed string
> and I receive an error.
> The error I get -
> "An error has occurred during report processing.
> Query execution failed for data set '....'.
> Line 1: Incorrect syntax near 's'.
> Unclosed quotation mark before the character string"."
> I know that I probably need to 'escape' the single quote, but I am
> unclear if I can do this on the data tab in report designer or if I
> have to do this through my views/stored procs in sql server. =A0After
> determining where to make the change, I will also need to know what
> the correct syntax is.
> Thanks so much for your help.
> Crystal
Go to the Data tab, and click the Properties button [...] for the
Dataset. Under the Parameters tab, you will see mappings between the
parameters used in the dataset, mapped to the Report Parameters. Note
that these are expressions, so you can put your own code in here to
"escape" the single quote.
What you will want to do is do is something like:
@.Pararm =3DReplace( Parameters!Param.Value, "'", "''" )
-- Scott

Monday, March 12, 2012

How to add parameters to a MDX query in RS 2005?

I'm currently struggling with parameters when doing reports based on SSAS
2005 in RS 2005.
How do I add a new parameter to an MDX query, after having built the query
using the wysiwig query builder? I could probably start all over again to
use the query builder, but I can't figure out how to create semi-dynamic
queries like I did with RS 2000 / AS 2000.
And is there a way to choose if a parameter should be multivalue when adding
it as a parameter?
Any good books focusing on Reporting Services and Analysis Services 2005?
Most of them focus on SQL based reports.
Kaisa M. Lindahl LervikHope you have tried puting "@." to the parameters this is basics and go to
report parameter from menu and can define multi value.
A book from "Brian Larson" of SSRS and SS BI is good book to start with and
your online help and samples are best resources for learning.
Amarnath
"Kaisa M. Lindahl Lervik" wrote:
> I'm currently struggling with parameters when doing reports based on SSAS
> 2005 in RS 2005.
> How do I add a new parameter to an MDX query, after having built the query
> using the wysiwig query builder? I could probably start all over again to
> use the query builder, but I can't figure out how to create semi-dynamic
> queries like I did with RS 2000 / AS 2000.
> And is there a way to choose if a parameter should be multivalue when adding
> it as a parameter?
> Any good books focusing on Reporting Services and Analysis Services 2005?
> Most of them focus on SQL based reports.
> Kaisa M. Lindahl Lervik
>
>|||I had problems with the whole strtomember syntax. Just making a parameter
didn't put this new parameter into the query, probably because I'd gone from
the editor to hand editing the query, and I couldn't figure out the syntax
of a new parameter.
Anyway, I found out how to make dynamic mdx queries the old way*. I'll check
out the book by Brian Larson, there's probably a more modern way of making
mdx based reports than the old school way I'm used to. ;)
*= Make a new data source with OLE DB instead of Analysis Services, and then
connect it to Analysis Services 9.0. Gives you back the good old text only
editor, which I prefer right now.
Kaisa M: Lindahl Lervik
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:FFF7458A-F34C-4CC7-8CA0-55C59B8C0106@.microsoft.com...
> Hope you have tried puting "@." to the parameters this is basics and go to
> report parameter from menu and can define multi value.
> A book from "Brian Larson" of SSRS and SS BI is good book to start with
> and
> your online help and samples are best resources for learning.
> Amarnath
> "Kaisa M. Lindahl Lervik" wrote:
>> I'm currently struggling with parameters when doing reports based on SSAS
>> 2005 in RS 2005.
>> How do I add a new parameter to an MDX query, after having built the
>> query
>> using the wysiwig query builder? I could probably start all over again to
>> use the query builder, but I can't figure out how to create semi-dynamic
>> queries like I did with RS 2000 / AS 2000.
>> And is there a way to choose if a parameter should be multivalue when
>> adding
>> it as a parameter?
>> Any good books focusing on Reporting Services and Analysis Services 2005?
>> Most of them focus on SQL based reports.
>> Kaisa M. Lindahl Lervik
>>

How to add parameter for file name for subscription

Hi,
I working on Report Delivery by "Report Server File Share".
I like to add parameters into the name.
for example,
report name is "order". there are paremeter name "startdate" and "endate".
I'd like to change the filename "order_startdate_12_1_06_enddate_12_2_06"
something like that.
Is there any way to attach parameters to FileName?
Thanks
KenHi Ken,
I am not sure if you can add a parameter to change the file name at
runtime after you have created the subscription.
I can suggest Data driven subscriptions where you can execute a query
which will return all these parameters to you from the data base. You
can specify a name for the report based on your requirements and this
column can be mapped to the FileName in the subscription which will
create a file witht that name.
If you dont know what a data driven subscription is this will get you
started.
http://msdn2.microsoft.com/en-us/library/ms156012.aspx
Hope this helps,
Virat
Ken wrote:
> Hi,
> I working on Report Delivery by "Report Server File Share".
> I like to add parameters into the name.
> for example,
> report name is "order". there are paremeter name "startdate" and "endate".
> I'd like to change the filename "order_startdate_12_1_06_enddate_12_2_06"
> something like that.
> Is there any way to attach parameters to FileName?
> Thanks
> Ken

Wednesday, March 7, 2012

How to add 'ALL' as report parameter in drop down with other parameters

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

Hi -

You should be able to add an "All Counties" option to your drop down list without a much of a performance hit.

For the dataset that is the basis for the parameter list, have something like this:
SELECT
County,
CountyId
FROM
Counties

UNION

SELECT
'(ALL)', -1
Now in the dataset that the report is based on, include something like this:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR CountyId = -1)
Of course you'll see performance benefits from wrapping these two statements in stored procedures.

HTH....

--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811

I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)


|||Joe,
Thank you very much.Explained in very good way.I will try this way.If any problems I will let you know.Thanks once again.
r sankar|||

hi Joe Webbon ,

I've faced this problem , and I'm searching for a better solution for it.


I think this solution is not right . I try it . but it didn't work.
Why?
so it could be :
WHERE (Country.CTRYIsn =98) ====== country no 98
or
WHERE (Country.CTRYIsn = -1) ====== ((((NO DATA))))
because if the report user choose 'ALL' in the drop down menu , the value willl be -1, so, anyone knows that the query results only bring the row which match the value. and because there is not -1 in the country field in the fact table, the results will be 0 ROWS

SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn = - 1)

NO DATA, u see?

-
my idea is :
SELECT
County,
cast (CountyId as varchar(9))
FROM
Counties
UNION
SELECT
'(ALL)', '%'
SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn LIKE @.CTRYIsn)

so it could be :
WHERE (Country.CTRYIsn LIKE 98) ====== country no 98
or
WHERE (Country.CTRYIsn LIKE %) ====== ALL
anyone can find another solution that can high the performance than my sol. , please say it !!!!!!

|||

Rather than comparing the data field to -1 it should have compared the parameter. ie

WHERE (Country.CTRYIsn LIKE @.CTRYIsn OR @.CTRYIsn = -1)

I think this would be be a better solution rather than passing a %.

Cheers

|||Hi,
I use dynamic SQL in the stored procedure to manage the performance issues. I have got multiple drop down with the "All" option. example:

if @.CTRYIsn != '%' begin

set @.vWhere = @.vWhere + ' and s.CTRYIsn = ' + char(39) + @.CTRYIsn + char(39)

end

If you use the new "Multi-Value" property, change this to handle cases where user selected multiple items. I yet have to work on that. I guess that the parameter list will have to be compared to the distinct count of counties to see if the count is 1 or = to the count of counties or in between. if = to 1, then use = if in between then use in(@.CTRYsn) else do not set any limit on the item. What I do not know yet is how to count the items in the parameter list. May be you could count the "," from the parameter list?

Regards,
Philippe

|||

thank u again,

I still can't understand , I think agian your statment are WRONG !!!!
did u try it , or u just propose a solution

dont say an example , My solution before is NOW on use.

Karim

|||Hi Karim -
You're absolutely right. The code I posted will not work as is. There was a typo in it. The code should read:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR @.CountyId = -1)
The typo was in the second part of the OR clause. It should have the parameter (@.CountyId) as shown above rather than the fieldname (CountyId) as shown in the original post.
When a user selects a specific CountyId in the dropdown, the first part of the OR condition will be satisified. When the user selects the ALL item in the dropdown, the second part of the OR condition will be satisfied for every row in the table.
The solution you posted will certainly return the appropriate resultset, but it will also incurr the performance hit associated with using LIKE. It's not nearly as efficient as comparing two integers.
HTH....and thanks for pointing out the typo!
--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811
I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)

||| (CountyId = @.CountyId OR @.CountyId = -1)
Actually, you may get better performance if you reverse the order, like this:
(@.CountyId = -1 OR CountyId = @.CountyId)
to take advantage of short-circuit evaluation of the OR operator. Because the expression "@.CountyId = -1" can be evaluated both ahead of time and just once, it may be faster.
For example, in SQL Server 2000, this:
declare @.value varchar(10)
set @.value='All'

select distinct patid from tx_history_all
where
@.value = 'All' or
cost_center_code = @.value
-- or @.value = 'All' is three times faster than this:

declare @.value varchar(10)
set @.value='All'
select distinct patid from tx_history_all
where
-- @.value = 'All' or
cost_center_code = @.value
or @.value = 'All'

|||Hey There --

I think you've gotten your "2000" answer already, so the following is just an FYI...You get multi-parameter select ("All", among other combinations) in 2005, making all the workarounds unnecessary.|||

Very interesting thread...Sounds like 2005 has this issue resolved!

But just for fun I would like to continue the "2000" workarounds...

You see, I was trying to get "(ALL)" or single item capabilities added to existing item range parameters. The user could indicate one item, all items, or a range of items. Here is what I came up with (it's kind of hokey looking but it works):

="select PONUMBER,ITEMNMBR,ITEMDESC,LOCNCODE,VENDORID,UOFM,QTYORDER,REQDATE from POP10110 (NOLOCK) WHERE QTYORDER > 0 " & IIf(Parameters!ItemStart.Value = "(ALL)","AND ITEMNMBR NOT LIKE "," AND ITEMNMBR BETWEEN '" & trim(Parameters!ItemStart.Value) & "' AND ") &
IIf(Parameters!ItemEnd.Value = "(ALL)","'" & trim(Parameters!ItemStart.Value) & "'","'" & trim(Parameters!ItemEnd.Value) & "'")

How to add 'ALL' as report parameter in drop down with other parameters

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

Hi -

You should be able to add an "All Counties" option to your drop down list without a much of a performance hit.

For the dataset that is the basis for the parameter list, have something like this:
SELECT
County,
CountyId
FROM
Counties

UNION

SELECT
'(ALL)', -1
Now in the dataset that the report is based on, include something like this:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR CountyId = -1)
Of course you'll see performance benefits from wrapping these two statements in stored procedures.

HTH....

--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811

I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)


|||Joe,
Thank you very much.Explained in very good way.I will try this way.If any problems I will let you know.Thanks once again.
r sankar|||

hi Joe Webbon ,

I've faced this problem , and I'm searching for a better solution for it.


I think this solution is not right . I try it . but it didn't work.
Why?
so it could be :
WHERE (Country.CTRYIsn =98) ====== country no 98
or
WHERE (Country.CTRYIsn = -1) ====== ((((NO DATA))))
because if the report user choose 'ALL' in the drop down menu , the value willl be -1, so, anyone knows that the query results only bring the row which match the value. and because there is not -1 in the country field in the fact table, the results will be 0 ROWS

SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn = - 1)

NO DATA, u see?

-
my idea is :
SELECT
County,
cast (CountyId as varchar(9))
FROM
Counties
UNION
SELECT
'(ALL)', '%'
SELECT BillOfLading.*
FROM Country INNER JOIN
BillOfLading ON Country.CTRYIsn = BillOfLading.CTRYIsn
WHERE (Country.CTRYIsn LIKE @.CTRYIsn)

so it could be :
WHERE (Country.CTRYIsn LIKE 98) ====== country no 98
or
WHERE (Country.CTRYIsn LIKE %) ====== ALL
anyone can find another solution that can high the performance than my sol. , please say it !!!!!!

|||

Rather than comparing the data field to -1 it should have compared the parameter. ie

WHERE (Country.CTRYIsn LIKE @.CTRYIsn OR @.CTRYIsn = -1)

I think this would be be a better solution rather than passing a %.

Cheers

|||Hi,
I use dynamic SQL in the stored procedure to manage the performance issues. I have got multiple drop down with the "All" option. example:

if @.CTRYIsn != '%' begin

set @.vWhere = @.vWhere + ' and s.CTRYIsn = ' + char(39) + @.CTRYIsn + char(39)

end

If you use the new "Multi-Value" property, change this to handle cases where user selected multiple items. I yet have to work on that. I guess that the parameter list will have to be compared to the distinct count of counties to see if the count is 1 or = to the count of counties or in between. if = to 1, then use = if in between then use in(@.CTRYsn) else do not set any limit on the item. What I do not know yet is how to count the items in the parameter list. May be you could count the "," from the parameter list?

Regards,
Philippe

|||

thank u again,

I still can't understand , I think agian your statment are WRONG !!!!
did u try it , or u just propose a solution

dont say an example , My solution before is NOW on use.

Karim

|||Hi Karim -
You're absolutely right. The code I posted will not work as is. There was a typo in it. The code should read:
SELECT
col1,
col2,
col3,
...,
coln
FROM
tab1
WHERE
(CountyId = @.CountyId OR @.CountyId = -1)
The typo was in the second part of the OR clause. It should have the parameter (@.CountyId) as shown above rather than the fieldname (CountyId) as shown in the original post.
When a user selects a specific CountyId in the dropdown, the first part of the OR condition will be satisified. When the user selects the ALL item in the dropdown, the second part of the OR condition will be satisfied for every row in the table.
The solution you posted will certainly return the appropriate resultset, but it will also incurr the performance hit associated with using LIKE. It's not nearly as efficient as comparing two integers.
HTH....and thanks for pointing out the typo!
--
Joe Webb
SQL Server MVP
http://www.sqlns.com

~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811
I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)||| (CountyId = @.CountyId OR @.CountyId = -1)
Actually, you may get better performance if you reverse the order, like this:
(@.CountyId = -1 OR CountyId = @.CountyId)
to take advantage of short-circuit evaluation of the OR operator. Because the expression "@.CountyId = -1" can be evaluated both ahead of time and just once, it may be faster.
For example, in SQL Server 2000, this:
declare @.value varchar(10)
set @.value='All'

select distinct patid from tx_history_all
where
@.value = 'All' or
cost_center_code = @.value
-- or @.value = 'All' is three times faster than this:

declare @.value varchar(10)
set @.value='All'
select distinct patid from tx_history_all
where
-- @.value = 'All' or
cost_center_code = @.value
or @.value = 'All'

|||Hey There --

I think you've gotten your "2000" answer already, so the following is just an FYI...You get multi-parameter select ("All", among other combinations) in 2005, making all the workarounds unnecessary.|||

Very interesting thread...Sounds like 2005 has this issue resolved!

But just for fun I would like to continue the "2000" workarounds...

You see, I was trying to get "(ALL)" or single item capabilities added to existing item range parameters. The user could indicate one item, all items, or a range of items. Here is what I came up with (it's kind of hokey looking but it works):

="select PONUMBER,ITEMNMBR,ITEMDESC,LOCNCODE,VENDORID,UOFM,QTYORDER,REQDATE from POP10110 (NOLOCK) WHERE QTYORDER > 0 " & IIf(Parameters!ItemStart.Value = "(ALL)","AND ITEMNMBR NOT LIKE "," AND ITEMNMBR BETWEEN '" & trim(Parameters!ItemStart.Value) & "' AND ") &
IIf(Parameters!ItemEnd.Value = "(ALL)","'" & trim(Parameters!ItemStart.Value) & "'","'" & trim(Parameters!ItemEnd.Value) & "'")

How to add ALL as report parameter in drop down

Hi ALL,
I would like to add 'ALL' to other report parameters.The other report parameters are counties.I would like to add 'all' so that user can select all counties from drop down.

I added union select 'ALL' to sub query.
in main query @.county='all' is it right or wrong.After I did this report is running very very slow.performance problem begins.
what exactly is the procedure to do.
thanks
r sankar

How are you using the counties? I do the same thing, but my countiesalso have a numerical county code. So I union the parameter to have thename as the label and an integer as the value. The query lookssomething like
Select 'All Counties' as nm_county, 0 as id_county
UNION
Select nm_county, id_county from dbo.county
The report still renders just as quickly, and I just check "If@.County = 0" in the stored procedure I use. Hope this helps.
|||Hi,
thank you very much for reply.I did not use @.county =0 in stored procedure .that is why it became slow.Now It is working fine.Thank you once again.If I get any more problems I will let you know.
thanks
sankar|||

You can also reference it directly in a query::

SELECT *
FROM Businesses
WHERE (county = @.county) or (@.county = 'ALL')

This way, you either get Businesses for a specific county or you get all businesses.

How to add additional functionality to parameter boxes

Is there a way to add additional functionality to the report parameter boxes?

For example, when a user enters an invalid choice into a report parameter box, I want a popup balloon that tells them to try again.

I know how to do this for a regular Winform combobox, but can I implement an interface to override the default behavior of the report parameter boxes?

Hey JordanBean... I'm trying to do the same thing. Kind of...

I also want to create a separate interface to override the default parameter behavior. I feel like there are just too many limitations on the default parameter interface.

I found out that you can set parameter values in the URL string by right-clicking on the report itself (not the parameters), click on Properties, copy and paste that URL, and you can see the parameter values embedded there. That means you could create your own interface and have it spit out its values into the URL string. The only down side is once you're there, the users don't have any more access to navigate the report pages, zoom in/out, or export to different formats. Then it basically becomes useless.

There must be a better way than this!

|||I agree. Is there not an interface that we can impelment to provide custom parameter textbox functionality?|||

The easiest way to do this is to Embed a ReportViewer control in your application and to provide a custom parameter UI. In this way, you have the ease of viewing reports without writing messy code to set URL properties, you get good debugging because you're using managed code controls. It also allows you to provide a custom parameters UI that looks and feels like it is part of the overall solution.

Hope that helps,

-Lukasz

how to add a where clause by parameter in a stored procedure

What i want is to add by parameter a Where clause and i can not find how to do it!
CREATE PROCEDURE [ProcNavigate]
(
@.id as int,
@.whereClause as char(100)
)
AS
Select field1, field2 Where fieldId = @.id /*and @.WhereClause */
GO

thx
What error did you get? That sproc defintion looks fine to me apart from the fact that you've missed the FROM clause from the parameterised SQL statement.

-Jamie|||thx for the reply.

You are right. I forgot the from clause.

CREATE PROCEDURE [ProcNavigate]
(
@.id as int,
@.whereClause as char(100)
)
AS
Select field1, field2 FROM Table1 Where fieldId = @.id /*and @.WhereClause */
GO
I get only a syntax error when checking the procedure syntax|||

SQL Server does not support "parameterizing" the WHERE clause or any syntactic construct.

You have to construct the SQL String using string concatenation operations and then execute the constructed string using the dynamic EXEC statement.

CREATE PROCEDURE [ProcNavigate]
(
@.id as int,
@.whereClause as char(100)
)
AS
BEGIN
DECLARE @.mdstring nvarchar(300);
set @.cmdstring = "SELECT field1, field2 FROM T WHERE fieldID = " + @.id +
" AND " + @.whereClause;
EXEC(@.cmdstring);
END
GO

|||Personally, I dislike the above mentioned method. Besides the fact that it opens you to all sorts of bad stuff.

What you can do is make the parameters nullable, and do a case statement on the where part of the clause:

create procedure pSomethingOrAnother
(
@.p_lID integer,
@.p_lWhereItem1 integer,
@.p_sWhereItem2 varchar(50)
)
as

set nocount on

select
t.Field1,
t.Field2
from
TableName t
where
t.FieldID = @.p_lID
and (case when ISNULL(@.p_lWhereItem1, 0) = 0 then 0 else t.FieldToCheck1 end) = ISNULL(@.p_lWhereItem1, 0)
and (case when ISNULL(@.p_lWhereItem2, '') = '' then '' else t.FieldToCheck2 end) = ISNULL(@.p_sWhereItem2, '')

set nocount off

No magic values, no string concatenation, no million if statements. The only time this won't work so well is when you are looking for the value NULL in a field, but you can separate those instances out with an IF statement for that field.

how to add a where clause by parameter in a stored procedure

What i want is to add by parameter a Where clause and i can not find how to do it!
CREATE PROCEDURE [ProcNavigate]
(
@.id as int,
@.whereClause as char(100)
)
AS
Select field1, field2 from table1 Where fieldId = @.id /*and @.WhereClause */
GO
any suggestion?What you're trying to do can only be done using dynamic SQL. Dynamic SQL is a pretty large topic, so here are a few links to get youstarted:
http://www.databasejournal.com/features/mssql/article.php/1438931
http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sommarskog.se/dynamic_sql.html

how to add a nvarchar parameter to ntext or text types?

please help >>

how to add a nvarchar parameter to ntext or text types like :

set @.ntext_param = @.ntext_param + @.nvarchar_param

You cannot declare variables of text/ntext/image data type in SQL Server and manipulate them. You can only have parameters of SPs or functions with these data types. You can however use UPDATETEXT to append a varchar/char/nvarchar/char/text/ntext/varbinary/binary value to text/ntext/image value.

In SQL Server 2005, you can use the new nvarchar(max) and nvarbinary(max) data types similar to regular character data types. This will allow you to use concatenation operators. These data types are replacement for text/ntext/image data types.

|||

Concatenation is not supported on ntext, but is supported on nvarchar(max). You can do the following:

set @.ntext_param = convert(nvarchar(max), @.ntext_param) + @.nvarchar_param

Friday, February 24, 2012

How to add a calender with a user parameter

Hello evry one,
Can any one help me how to add a calender as a list of
values,to an user parameter in reports. I am passing a parameter
called effective date. for that parameter i need calender as a list of
value. Please any one help on this..
thanks
BalajiThis is built into RS 2005. Just go to layout view, Report Menu ->Report
Parameters and change the data type to datetime. You will now have a
calendar. If you are on RS 2000 you are out of luck.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
<rampaleee@.gmail.com> wrote in message
news:1193739093.504989.145020@.o38g2000hse.googlegroups.com...
> Hello evry one,
> Can any one help me how to add a calender as a list of
> values,to an user parameter in reports. I am passing a parameter
> called effective date. for that parameter i need calender as a list of
> value. Please any one help on this..
> thanks
> Balaji
>