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

Monday, March 19, 2012

Encrypting a data

Hi,

I have creating a stored procedure in sql server 2005 to encrypt a parameter value that comes from an asp.net page. this value is of type varchar.

Now i have declared a paramater as varbinary to accept this value in the stored procedure. And encrypting it using symmetric key which is encrypted by certificate.

Now when i enter a value into the textbox in asp.net page. it shows

"implicit conversion from varchar to varbinary not possible" pls tell me what is the solution? do i have to convert the value in vb code while accessing the value of the textbox or do i have to convert the value while passing the value when call stored procedure.

pls tell me the solution so that i don't jave to change any coding in vb.

some solution in sql server itselt.

Thank you

Gaurav

If you're passing a varchar to the stored procedure, then rewrite the stored procedure to accept a varchar.

Thanks
Laurentiu

|||

But i have to encrypt that value - the value that is coming from a varchar parameter.

And encryption works on varbinary data type. so do i need to convert that parameter to varbinary in the stored procedure.

Infact i even tried that but it is showing the same result implicit conversion not allowed.

Pls give me a solution. where i could pass a varchar data type value to a stored procedure and encrypt it in the stored procdure.

Thanks

Gaurav

|||

You can encrypt varchar values; it is not true that encryption works only on varbinary data. See the BOL article for EncryptByKey:

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

varchar is explicitly listed as an accepted type for the cleartext data, so you just need to rewrite your procedure to accept a varchar value. Converting the varchar data to varbinary in the procedure does not help, because the problem happens earlier when you pass the varchar value to the procedure that expects a varbinary. If you don't want to change the procedure code to expect a varchar, then you have to explicitly cast the varchar to varbinary before you pass it to the procedure.

For an example that encrypts varchar data, see http://blogs.msdn.com/lcris/archive/2005/12/16/504692.aspx. There are other examples on my blog that encrypt varchar data besides that one.

Thanks
Laurentiu

Sunday, February 19, 2012

Enable parameter selection

I have two reports. On Report1, I have a hyperlink action that brings up
Report2, passing the required parameters it needs. But when Report2 is shown,
I don't have the ability to change the parameters, E.g. in Report2, I have a
parameter in a list with a Show\Hide options. When getting redirected from
Report1, the default is set to hide. When I'm in Report 2, I then want to
change it to Show, but the parameter "section" is not on the report header.
Looking at the link, I can see the following
...%3d0%26rc%253aParameters%3dFalse%26rc%253aReplacementRoot%3dhttp...When I
change the False to True, I can then see the parameter area, but I'm not sure
how to enable it in the report. Can't seem to find the property I need to
change.Use jump to URL instead of jump to report and you can set this the way you
want.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Alex" <alex_dinu@.adp.com.(nospam)> wrote in message
news:EFDE9B94-308C-4050-9214-F7B9913F3659@.microsoft.com...
>I have two reports. On Report1, I have a hyperlink action that brings up
> Report2, passing the required parameters it needs. But when Report2 is
> shown,
> I don't have the ability to change the parameters, E.g. in Report2, I have
> a
> parameter in a list with a Show\Hide options. When getting redirected from
> Report1, the default is set to hide. When I'm in Report 2, I then want to
> change it to Show, but the parameter "section" is not on the report
> header.
> Looking at the link, I can see the following
> ...%3d0%26rc%253aParameters%3dFalse%26rc%253aReplacementRoot%3dhttp...When
> I
> change the False to True, I can then see the parameter area, but I'm not
> sure
> how to enable it in the report. Can't seem to find the property I need to
> change.

Friday, February 17, 2012

Empty values in XML

Hi,
Trying to pass XML as parameter to stored procedure and get the result set.
I want to allow null values. Here is the problem: when I leave a value blank
(between the <Score> and </Score> tags) it will return 0 instead of <NULL>
... See code below.
What am I doing wrong here?
Thanks in advance!
Joost
CREATE PROCEDURE dbo.Test
AS
DECLARE @.i int
DECLARE @.ScoresXML nvarchar (4000)
SET @.ScoresXML = '<Scores><Score><ID>1</ID><Result></Result></Score></Scores>'
EXEC sp_xml_preparedocument @.i OUTPUT, @.ScoresXML
SELECT
ID,
Result
FROM
OPENXML (@.i, '/Scores/Score', 2)
WITH
(IDint,
Result float)
EXEC sp_xml_removedocument @.i
Hello JoostK,
SQL Server 2000 or SQL Server 2005?
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||SQL 2000
Thanks,
Joost
"Kent Tegels" <ktegels@.develop.com> schreef in bericht
news:b87ad741c6fb8c81b916f5cc940@.news.microsoft.co m...
> Hello JoostK,
> SQL Server 2000 or SQL Server 2005?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
|||Hi Kent,
Using SQL2000
Thanks, Joost
"Kent Tegels" wrote:

> Hello JoostK,
> SQL Server 2000 or SQL Server 2005?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
>
|||Hello JoostK,

> Hi,
> Trying to pass XML as parameter to stored procedure and get the result
> set. I want to allow null values. Here is the problem: when I leave a
> value blank (between the <Score> and </Score> tags) it will return 0
> instead of <NULL> ... See code below.
> What am I doing wrong here?
In your table, you're asking "what's the value of the Score element", which
isn't null because it does exist. What you want is "what's the value of
the text node of the element Score". To fix this, all you need do is write
your table as:
WITH
(IDint,
Result int 'text()')
And it should give you what you want.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

Empty values in XML

Hi,
Trying to pass XML as parameter to stored procedure and get the result set.
I want to allow null values. Here is the problem: when I leave a value blank
(between the <Score> and </Score> tags) it will return 0 instead of <NULL>
... See code below.
What am I doing wrong here?
Thanks in advance!
Joost
CREATE PROCEDURE dbo.Test
AS
DECLARE @.i int
DECLARE @.ScoresXML nvarchar (4000)
SET @.ScoresXML = '<Scores><Score><ID>1</ID><Result></Result></Score></Scores
>'
EXEC sp_xml_preparedocument @.i OUTPUT, @.ScoresXML
SELECT
ID,
Result
FROM
OPENXML (@.i, '/Scores/Score', 2)
WITH
(ID int,
Result float)
EXEC sp_xml_removedocument @.iHello JoostK,
SQL Server 2000 or SQL Server 2005?
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||SQL 2000
Thanks,
Joost
"Kent Tegels" <ktegels@.develop.com> schreef in bericht
news:b87ad741c6fb8c81b916f5cc940@.news.microsoft.com...
> Hello JoostK,
> SQL Server 2000 or SQL Server 2005?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>|||Hi Kent,
Using SQL2000
Thanks, Joost
"Kent Tegels" wrote:

> Hello JoostK,
> SQL Server 2000 or SQL Server 2005?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
>|||Hello JoostK,

> Hi,
> Trying to pass XML as parameter to stored procedure and get the result
> set. I want to allow null values. Here is the problem: when I leave a
> value blank (between the <Score> and </Score> tags) it will return 0
> instead of <NULL> ... See code below.
> What am I doing wrong here?
In your table, you're asking "what's the value of the Score element", which
isn't null because it does exist. What you want is "what's the value of
the text node of the element Score". To fix this, all you need do is write
your table as:
WITH
(ID int,
Result int 'text()')
And it should give you what you want.
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

empty status of a variable

The example bellow will receive a parameter.

create procedure usp_InsertProducts
@.SKU varchar(30)

Now how do I check whether is @.SKU empty or not.

Your help is kindly appreciated.

Regards

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***> how do I check whether is @.SKU empty or not.

IF @.sku IS NULL ...

or

IF @.sku = '' ...

depending on what you mean by "empty".

To differentiate between a NULL and no value specified you could
provide a default using some invalid token to represent the missing
value:

CREATE PROCEDURE usp_InsertProducts
@.sku VARCHAR(30) = '<Unspecified>'
AS ...

IF @.sku = '<Unspecified>'
...

--
David Portas
SQL Server MVP
--

Wednesday, February 15, 2012

Empty multi-value parameter

Several people have asked about this, but I have not seen a response that works. I have several parameters that I want to use as filters. If a particular filter parameter is not entered, the report should not apply a filter on that criterion. It works fine to create a single value parameter which allows null, and use the following in SQL:

WHERE ( [Field1] = @.Field1_Filter OR @.Field1_Filter IS NULL )

How can the same effect be achieved for a multi-value parameter? If you try to create a multi-value parameter which allows null, the report builder gives an error. I can't use "allow blank value" because some of my parameters are integer parameters. Without the allow null, the report generator requires me to enter at least one value. So I don't know how you can get a value of "not entered" into a multi-value parameter.

I also don't know how you would check for the "not entered". Someone suggested the following SQL:

WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_Filter IS NULL )

This generates an error when generating the report if multiple values are entered for the parameter (the normal condition). The error is " An expression of non-boolean type specified in a context where a condition is expected, near ',' ".

How is this supposed to be done?

Thanks for any insight

Would the following work?

WHERE (

[Field1] in (@.Field1_Filter)

OR (select count(*) from table where [Field1] in (@.Field1_Filter)) = 0

)

Or if that's too expensive, you might add an extra query parameter and pass in the following expression:

=Parameters!Field1_Filter.Value.Count

Then your SQL could read:

WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_FilterCount = 0 )

|||

Dont use the filter in the SQL query. Instead keep your SQL query as a simple select statement and implement the filter in the dataset Filter using expressions like this:

For example, if your SQL query is "SELECT * FROM Table 1 WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_Filter IS NULL )", change it to "SELECT * FROM Table1"

Now edit the dataset and go to Filter tab.

Under expression type this:

=IIf(Parameters!Field1_Filter.Value <> Nothing and Parameters!Field1_Filter.Count > 0, Fields!Field1.Value, 1)

Under Operator select "IN"

Under Value type this:

=IIf(Parameters!Field1_Filter.Value <> Nothing and Parameters!Field1_Filter.Count > 0, Parameters!Field1_Filter.Value, 1)

This way, when the filter parameter is null/nothing or count = 0, 1=1 will be evaluated which means no filter condition is applied.

Shyam

|||Thanks for the suggestions.

furmangg:

Your first suggestion wouldn't work because it would return everything anytime the filter didn't match, not just when the filter is empty.

I didn't think about using the count of the multivalue parameter. I think it's an array, so that could work either in the query (using another query parameter) or in a report filter. But how do I get an empty array in there? I'm using integer parameters. I can't set the parameter to allow null, and when I preview the report and leave the parameter blank, it tells me to enter at least one value. I tried it with string parameters, and the report just doesn't run in preview if you don't enter any values, even if you choose "allow blank".

How do you specify "empty" for a multivalue parameter?
|||Anyone have any ideas? Can someone at least confirm that this is a problem and not some screwy setup on my machine?
|||

If you set allow null or allow blank for your multi-valued parameter, one of those values must be null or blank. For example, if your parameter is getting its values from a query, make the query to return one more row with blank value or null value. Or if your list of values is non-queried, add another value to the list with blank or null value.

Shyam

|||Has anyone found a solution for this as I am having the same problem.

I have a multi-value parameter (Dim1Code) that is populated from a query:

SELECT
Dim1Code,
Dim1Code + ', ' + Description AS Description
FROM
Dim1

For some clients the query returns no data (which is fine) and so the drop down list is empty.

I have another parameter (EmployeeList) based on the following query:

SELECT
E.EmployeeCode,
E.EmployeeCode + ' - ' + E.Lastname + ', ' + E.Firstnames AS Name
FROM
Employee E
WHERE
Dim1Code IN (@.Dim1Code)

If the Dim1Code list is empty then it should return all employees, and I have not been able to find a way to get this working.

I have tried adding a union statement to the first query to also return a null row, but it wont let me set the "Allow Null" property on my parameter (I get an error as this is an invalid option for multi-value parameters).

If I set "Allow Blank" for my parameter and then run the report I am told that I need to select a value for the Dim1Code parameter.

If I union my first select with a hard coded value like "<None>" and change my second select statement to:

WHERE
Dim1Code IN (@.Dim1Code) OR @.Dim1Code = '<None>'

I then get an error when I try to run the report:

"An expression of non-boolean type specified in a context where a condition is expected, near ','"

I have tried the filtering options suggested further up in this thread and none of them worked for me either.

Is there really no way of having a valid "None" or "Blank" or "Null" option for multi-value parameters?

Why are multi-value parameters ALWAYS required to have a value?
|||

How about the following for the parameter query:

SELECT
Dim1Code,
Dim1Code + ', ' + Description AS Description
FROM
Dim1

union all

SELECT
'' as Dim1Code,
'-All Codes-' AS Description

WHERE (select count(*) from Dim1) = 0

Then the main query would read:


SELECT
E.EmployeeCode,
E.EmployeeCode + ' - ' + E.Lastname + ', ' + E.Firstnames AS Name
FROM
Employee E
WHERE
Dim1Code IN (@.Dim1Code)

OR '' in (@.Dim1Code)

Empty multi-value parameter

Several people have asked about this, but I have not seen a response that works. I have several parameters that I want to use as filters. If a particular filter parameter is not entered, the report should not apply a filter on that criterion. It works fine to create a single value parameter which allows null, and use the following in SQL:

WHERE ( [Field1] = @.Field1_Filter OR @.Field1_Filter IS NULL )

How can the same effect be achieved for a multi-value parameter? If you try to create a multi-value parameter which allows null, the report builder gives an error. I can't use "allow blank value" because some of my parameters are integer parameters. Without the allow null, the report generator requires me to enter at least one value. So I don't know how you can get a value of "not entered" into a multi-value parameter.

I also don't know how you would check for the "not entered". Someone suggested the following SQL:

WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_Filter IS NULL )

This generates an error when generating the report if multiple values are entered for the parameter (the normal condition). The error is " An expression of non-boolean type specified in a context where a condition is expected, near ',' ".

How is this supposed to be done?

Thanks for any insight

Would the following work?

WHERE (

[Field1] in (@.Field1_Filter)

OR (select count(*) from table where [Field1] in (@.Field1_Filter)) = 0

)

Or if that's too expensive, you might add an extra query parameter and pass in the following expression:

=Parameters!Field1_Filter.Value.Count

Then your SQL could read:

WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_FilterCount = 0 )

|||

Dont use the filter in the SQL query. Instead keep your SQL query as a simple select statement and implement the filter in the dataset Filter using expressions like this:

For example, if your SQL query is "SELECT * FROM Table 1 WHERE ( [Field1] IN (@.Field1_Filter) OR @.Field1_Filter IS NULL )", change it to "SELECT * FROM Table1"

Now edit the dataset and go to Filter tab.

Under expression type this:

=IIf(Parameters!Field1_Filter.Value <> Nothing and Parameters!Field1_Filter.Count > 0, Fields!Field1.Value, 1)

Under Operator select "IN"

Under Value type this:

=IIf(Parameters!Field1_Filter.Value <> Nothing and Parameters!Field1_Filter.Count > 0, Parameters!Field1_Filter.Value, 1)

This way, when the filter parameter is null/nothing or count = 0, 1=1 will be evaluated which means no filter condition is applied.

Shyam

|||Thanks for the suggestions.

furmangg:

Your first suggestion wouldn't work because it would return everything anytime the filter didn't match, not just when the filter is empty.

I didn't think about using the count of the multivalue parameter. I think it's an array, so that could work either in the query (using another query parameter) or in a report filter. But how do I get an empty array in there? I'm using integer parameters. I can't set the parameter to allow null, and when I preview the report and leave the parameter blank, it tells me to enter at least one value. I tried it with string parameters, and the report just doesn't run in preview if you don't enter any values, even if you choose "allow blank".

How do you specify "empty" for a multivalue parameter?
|||Anyone have any ideas? Can someone at least confirm that this is a problem and not some screwy setup on my machine?
|||

If you set allow null or allow blank for your multi-valued parameter, one of those values must be null or blank. For example, if your parameter is getting its values from a query, make the query to return one more row with blank value or null value. Or if your list of values is non-queried, add another value to the list with blank or null value.

Shyam

|||Has anyone found a solution for this as I am having the same problem.

I have a multi-value parameter (Dim1Code) that is populated from a query:

SELECT
Dim1Code,
Dim1Code + ', ' + Description AS Description
FROM
Dim1

For some clients the query returns no data (which is fine) and so the drop down list is empty.

I have another parameter (EmployeeList) based on the following query:

SELECT
E.EmployeeCode,
E.EmployeeCode + ' - ' + E.Lastname + ', ' + E.Firstnames AS Name
FROM
Employee E
WHERE
Dim1Code IN (@.Dim1Code)

If the Dim1Code list is empty then it should return all employees, and I have not been able to find a way to get this working.

I have tried adding a union statement to the first query to also return a null row, but it wont let me set the "Allow Null" property on my parameter (I get an error as this is an invalid option for multi-value parameters).

If I set "Allow Blank" for my parameter and then run the report I am told that I need to select a value for the Dim1Code parameter.

If I union my first select with a hard coded value like "<None>" and change my second select statement to:

WHERE
Dim1Code IN (@.Dim1Code) OR @.Dim1Code = '<None>'

I then get an error when I try to run the report:

"An expression of non-boolean type specified in a context where a condition is expected, near ','"

I have tried the filtering options suggested further up in this thread and none of them worked for me either.

Is there really no way of having a valid "None" or "Blank" or "Null" option for multi-value parameters?

Why are multi-value parameters ALWAYS required to have a value?
|||

How about the following for the parameter query:

SELECT
Dim1Code,
Dim1Code + ', ' + Description AS Description
FROM
Dim1

union all

SELECT
'' as Dim1Code,
'-All Codes-' AS Description

WHERE (select count(*) from Dim1) = 0

Then the main query would read:


SELECT
E.EmployeeCode,
E.EmployeeCode + ' - ' + E.Lastname + ', ' + E.Firstnames AS Name
FROM
Employee E
WHERE
Dim1Code IN (@.Dim1Code)

OR '' in (@.Dim1Code)