Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Friday, March 30, 2012

Need help constructing stored procedure

Hi,

I need to construct a stored procedure that will accept a set of comma seperated numbers. What I would like to do is something like this

create procedure shopping_cart(@.contents as varchar) as
select dvd_title
from movie_dvd
where dvd_detail_id in (@.contents)

dvd_detail_id is defined as int in the table.
The problem is if I declare @.contents as varchar, the procedure only recognizes the first number and ignores the others. Does anyone know how to get around this?

Thanks

Dan@.array is your @.contents...you need to pass the separator too..it can be a ',' or '-' etc


Create procedure shopping_cart (@.Array varchar(1000), @.separator char(1) ) AS

set nocount on
-- @.Array is the array we wish to parse
-- @.Separator is the separator charactor such as a comma
declare @.separator_position int -- This is used to locate each separator character
declare @.array_value varchar(1000) -- this holds each array value as it is returned

-- For my loop to work I need an extra separator at the end. I always look to the
-- left of the separator character for each array value
set @.array = @.array + @.separator

-- Loop through the string searching for separtor characters
while patindex('%' + @.separator + '%' , @.array) <> 0
begin

-- patindex matches the a pattern against a string
select @.separator_position = patindex('%' + @.separator + '%' , @.array)
select @.array_value = left(@.array, @.separator_position - 1)

-- This is where you process the values passed.
-- Replace this select statement with your processing
-- @.array_value holds the value of this element of the array
select Array_Value = @.array_value

-- This replaces what we just processed with and empty string
select @.array = stuff(@.array, 1, @.separator_position, '')
end

set nocount off
GO

hth|||I did the following on some other project

create procedure shopping_cart(@.contents as varchar) as
select dvd_title
from movie_dvd
where CharIndex(',' + Cast(dvd_detail_id as varchar(3)) + ',', @.contents) > 0

In the above case you should be sure that the values passed in are going to have , next to it. For eample, it should be ,1,2,3,

Does the above make sense?

AP

Monday, March 19, 2012

Need all rows within each group to be shown on 1 page

Hi,

I have data that is grouped by a code number. One of the code numbers have over 600 rows, while other code numbers have around 10 to 20 rows within it.

When I run the report the code number that has over 600 rows gets split over 2 pages while the other code numbers each get their own page.

How do I make it so that when I run the report the code number that has over 600 rows gets all displayed on the 1 page instead of being split over 2?

Thanks

Ben.

can anyone help please?|||

Hi ben22,

I'm afraid there is not really a functionality in Reporting Services that does this. I know this is a lack in Reporting Services.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

Hi Ben

Do you just want it to display on 1 page in the browser or
do you require this for printing aswell?

If it is for viewing purposes only, you can try to set the
'Interactive Page size' in the report properties to have a higher width.

G

|||need it both for display in the browser and for printing, as when it gets exported to excell it needs to be in the same sheet instead of being expanded over 2. This is because a certain value in the row gets summed at the end and I need that sum to include all the rows within the group, as when it splits over 2 pages I get two different sums where they should be altogether.|||

Hi ben,

As mentioned before, it is not possible to make the page size dynamic for printing and viewing at the same time.

You mentioned that you receive 2 sum results. It is possible to only have only a total line at the end in case of on each page.

For example:
When you use a Table you can set the total in the Table footer. Even if the table overlaps multiple pages, it will only be displayed at the last page.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

Sorry, I should of explain things a bit better before. By groups I meant I have 1 group in the table. This group breaks the data up by the unique field assigned to each data item and uses a group footer to do the sum. For example:

I have 800 cars, 600 are red 100 are blue and 100 are green. So when I run the report is looks like this

Page 1

RED

Name | Model | Price

Car1 | c1 | 20000

Car2 | c2 | 30000

…

Car400 | c400 | 15000

-

Total Price: 3000000

Page 2

RED

Name | Model | Price

Car401 | c401 | 20000

Car402 | c402 | 30000

…

Car600 | c600 | 15000

-

Total Price: 1500000

Page 3

BLUE

Name | Model | Price

Car1 | c1 | 10000

Car2 | c2 | 30000

…

Car100 | c100 | 40000

-

Total Price: 1000000

Page 4

GREEN

Name | Model | Price

Car1 | c1 | 25000

Car2 | c2 | 17000

…

Car100 | c100 | 40000

-

Total Price: 1200000

As you can see there are 4 pages. It splits the RED cars up over 2 pages giving the 2 different sums ie: cars 1 – 400 with the sum 3000000 and then cars 401 – 600 with the sum 1500000. I want my report to work so that the RED cars are all together and not on different pages, so altogether there are only 3 pages. So to look like this:

Page 1

RED

Name | Model | Price

Car1 | c1 | 20000

Car2 | c2 | 30000

…

Car600 | c600 | 15000

-

Total Price: 4500000

Page 2

BLUE

Name | Model | Price

Car1 | c1 | 10000

Car2 | c2 | 30000

…

Car100 | c100 | 40000

-

Total Price: 1000000

Page 3

GREEN

Name | Model | Price

Car1 | c1 | 25000

Car2 | c2 | 17000

…

Car100 | c100 | 40000

-

Total Price: 1200000

|||

Hi,

It is not possible to force a group on 1 page but it is possible to have only 1 total per group. You need to set the Color field in the expresion of the group. When you then look at the group footer, you will see that the total is done on group base.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

Geert Verhoeven wrote:

It is not possible to force a group on 1 page but it is possible to have only 1 total per group. You need to set the Color field in the expresion of the group. When you then look at the group footer, you will see that the total is done on group base.

Sorry but I dont really understand what you have said or how to implement it

|||

Hi,

What I mean is that you can not force the contents of a group to be on 1 page. Although the problem you have that the total is displayed on each page can be avoided by using the footer of the group. When you set the total in the group of the footer, only at the end of the group a total will be displayed and not at the end of each page.

Hope this is more clear.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||im using a group a footer and it still displays the total at the end of each page, not at the end of the group

Wednesday, March 7, 2012

Need a So-Called SSN Encryption

Hello, perhaps you guys have heard this before in the past, but here is
what I'm looking for.

I have a SQL 2000 table with Social security numbers. We need to
create a Member ID using the Member's real SSN but since we are not
allowed to use the exact SSN, we need to add 1 to each number in the
SSN. That way, the new SSN would be the new Member ID.

For example:

if the real SSN is: 340-53-7098 the MemberID would be 451-64-8109.

Sounds simply enough, but I can't seem to get it straight.

I need this number to be created using a query, as this query is a
report's record source.

Again, any help would be appreciated it.ILCSP@.NETZERO.NET wrote:
> Hello, perhaps you guys have heard this before in the past, but here is
> what I'm looking for.
> I have a SQL 2000 table with Social security numbers. We need to
> create a Member ID using the Member's real SSN but since we are not
> allowed to use the exact SSN, we need to add 1 to each number in the
> SSN. That way, the new SSN would be the new Member ID.

That's almost totally ineffective if the idea is to protect the SSN
from disclosure. Why don't you use a hash of the number instead? A
secure one like SHA1 for example.

If you must, then something like this should do it:

REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
REPLACE(@.ssn,'0','#')
,'9','0'),'8','9'),'7','8'),'6','7'),'5','6')
,'4','5'),'3','4'),'2','3'),'1','2'),'#','1')

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--|||I agree - it's pretty lame that this method allows you to "comply" with
the policy.

Then again, when my school switched from using SSNs to "Student IDs",
it was a nightmare--but only because no one could remember them.|||Hi David, I totally agree with you. However, this does the job. I
tested and the numbers do get increased by 1.

And to think I was trying to do Case..WHEN.. END statements. Gosh!|||One method is to create a table of single, pairs, triplets etc. like
this

CREATE TABLE TripletEncode
(in_triplet CHAR(3) NOT NULL PRIMARY KEY
CHECK(in_triplet LIKE '[0-9][0-9][0-9]',
out_triplet CHAR(3) NOT NULL);

Break the input into substrings, and replace the characters with the
out_triplet. It is not a great system. Given some sample data, you can
figure out the areas and other repeated parts of SSN, phone numbers,
etc.

There are some modifications, like putting the last digit in front, or
using the last digit to pick which encoding to use from a table with a
extra column that goes from 0 to 9. The real trick is to be sure that
the encodings are reversible.|||Hi

Having nothing better to do this afternoon I wrote a function called
CodeDecodeSSN which has the advantage that it can be used to go from SSN to
Encrypted SSN and then from Encrypted SSN back to the originalSSN.

It has the disadvantage that the Encrypted SSN may contain Hex characters A
through F).

It probably is also slow.

The mask is arbitrary, you can select any number of the form ###-##-####'
(these must be numeric digits 0 to 9) but it must remain the same through
the life of the application.

Modify this line to set your own mask.
>set @.mask = '123-45-6789'

Basically the function works by doing a bitwise XOR of each digit in the
Source SSN against the corresponding digit in the @.mask.

Using a hash code such as David suggested is probably a better idea, but
like i said, I had nothing better to do this afternoon. ( I wish someone
would offer me a job :) )

select dbo.CodeDecodeSSN('123-46-7890')
Produces 000-03-1F19

select dbo.CodeDecodeSSN('000-03-1F19')
Produces 123-46-7890

create Function CodeDecodeSSN(@.src varchar(11))
returns varchar(11)
begin
declare @.mask varchar(11)
declare @.rv varchar(11)
set @.mask = '123-45-6789'
declare @.i int
declare @.j int
declare @.c int
declare @.c1 char(1)
declare @.c3 char(3)
declare @.m int
set @.i = 1
set @.rv = ''
while @.i <= 11
begin
if @.i = 4 or @.i = 7
set @.rv = @.rv + '-'
else
begin
Set @.c3 = '%' + substring(@.src,@.i,1) + '%'
set @.c = PatIndex(@.c3,'0123456789ABCDEF') -1
Set @.m = substring(@.mask,@.i,1)
set @.c = @.c ^ @.m
if @.c > 9
begin
set @.c1 = char(ascii('A') + @.c - 10)
end
else
begin
set @.C1 = cast(@.c as char(1))
end
set @.rv = @.rv + @.c1
end
set @.i = @.i + 1
end
return @.RV
end
--
-Dick Christoph
<ILCSP@.NETZERO.NET> wrote in message
news:1143739733.710415.9180@.z34g2000cwc.googlegrou ps.com...
> Hello, perhaps you guys have heard this before in the past, but here is
> what I'm looking for.
> I have a SQL 2000 table with Social security numbers. We need to
> create a Member ID using the Member's real SSN but since we are not
> allowed to use the exact SSN, we need to add 1 to each number in the
> SSN. That way, the new SSN would be the new Member ID.
> For example:
> if the real SSN is: 340-53-7098 the MemberID would be 451-64-8109.
> Sounds simply enough, but I can't seem to get it straight.
> I need this number to be created using a query, as this query is a
> report's record source.
> Again, any help would be appreciated it.|||ILCSP@.NETZERO.NET wrote:
> Hi David, I totally agree with you. However, this does the job.

Actually no, it doesn't do the job. The point of the policy is that
your company will be in line for a major lawsuit if (when) your
database server is hacked and the SSNs are stolen and your customers
start falling victim to identity theft. Knowing this, someone wrote a
policy that you are not allowed to store SSNs. You have NOT complied
with that policy.

Someone else already offered you one very simple solution, you could
hash the SSNs and use the hash as an ID rather than the SSN. The only
thing I would add is that you should hold on to the last four digits of
the SSN and use them to resolve collisions. That you refuse to
implement this simple and effective solution actually makes me just a
little angry. I'm angry knowing that people like you, who don't care
to protect *my* personal information, are often in positions where you
have charge of my personal information.

Incidentally, the "perfect" solution to this problem can be found in
Bruce Schneier's book Applied Cryptography. I don't have it in front
of me right now but the gist of it is that you not only hash the SSNs
but you use the SSN as a key to encrypt the rest of the data. With
this system, when someone steals your user database, they wont get
anything - not even names and addresses.

Please look into this. It's the right thing to do.|||Hi

Oh one more thing, this method is not particularily secure. If a hacker knew
one SSN and the associated encrypted SSN he/she could XOR them together to
determine the Mask used and then use this value to decrypt all the encrypted
SSNs in the table.

-Dick Christoph

"DickChristoph" <dchristo99@.yahoo.com> wrote in message
news:dmhXf.37756$Eg2.8093@.tornado.rdc-kc.rr.com...
> Hi
> Having nothing better to do this afternoon I wrote a function called
> CodeDecodeSSN which has the advantage that it can be used to go from SSN
> to Encrypted SSN and then from Encrypted SSN back to the originalSSN.
> It has the disadvantage that the Encrypted SSN may contain Hex characters
> A through F).
> It probably is also slow.
> The mask is arbitrary, you can select any number of the form ###-##-####'
> (these must be numeric digits 0 to 9) but it must remain the same through
> the life of the application.
> Modify this line to set your own mask.
>>set @.mask = '123-45-6789'
> Basically the function works by doing a bitwise XOR of each digit in the
> Source SSN against the corresponding digit in the @.mask.
> Using a hash code such as David suggested is probably a better idea, but
> like i said, I had nothing better to do this afternoon. ( I wish someone
> would offer me a job :) )
> select dbo.CodeDecodeSSN('123-46-7890')
> Produces 000-03-1F19
> select dbo.CodeDecodeSSN('000-03-1F19')
> Produces 123-46-7890
> create Function CodeDecodeSSN(@.src varchar(11))
> returns varchar(11)
> begin
> declare @.mask varchar(11)
> declare @.rv varchar(11)
> set @.mask = '123-45-6789'
> declare @.i int
> declare @.j int
> declare @.c int
> declare @.c1 char(1)
> declare @.c3 char(3)
> declare @.m int
> set @.i = 1
> set @.rv = ''
> while @.i <= 11
> begin
> if @.i = 4 or @.i = 7
> set @.rv = @.rv + '-'
> else
> begin
> Set @.c3 = '%' + substring(@.src,@.i,1) + '%'
> set @.c = PatIndex(@.c3,'0123456789ABCDEF') -1
> Set @.m = substring(@.mask,@.i,1)
> set @.c = @.c ^ @.m
> if @.c > 9
> begin
> set @.c1 = char(ascii('A') + @.c - 10)
> end
> else
> begin
> set @.C1 = cast(@.c as char(1))
> end
> set @.rv = @.rv + @.c1
> end
> set @.i = @.i + 1
> end
> return @.RV
> end
> --
> -Dick Christoph
> <ILCSP@.NETZERO.NET> wrote in message
> news:1143739733.710415.9180@.z34g2000cwc.googlegrou ps.com...
>> Hello, perhaps you guys have heard this before in the past, but here is
>> what I'm looking for.
>>
>> I have a SQL 2000 table with Social security numbers. We need to
>> create a Member ID using the Member's real SSN but since we are not
>> allowed to use the exact SSN, we need to add 1 to each number in the
>> SSN. That way, the new SSN would be the new Member ID.
>>
>> For example:
>>
>> if the real SSN is: 340-53-7098 the MemberID would be 451-64-8109.
>>
>> Sounds simply enough, but I can't seem to get it straight.
>>
>> I need this number to be created using a query, as this query is a
>> report's record source.
>>
>> Again, any help would be appreciated it.
>>|||SHA hash function:
http://www.sqlservercentral.com/col...oolkitpart4.asp
Encryption functions:
http://www.sqlservercentral.com/col...oolkitpart1.asp

<ILCSP@.NETZERO.NET> wrote in message
news:1143739733.710415.9180@.z34g2000cwc.googlegrou ps.com...
> Hello, perhaps you guys have heard this before in the past, but here is
> what I'm looking for.
> I have a SQL 2000 table with Social security numbers. We need to
> create a Member ID using the Member's real SSN but since we are not
> allowed to use the exact SSN, we need to add 1 to each number in the
> SSN. That way, the new SSN would be the new Member ID.
> For example:
> if the real SSN is: 340-53-7098 the MemberID would be 451-64-8109.
> Sounds simply enough, but I can't seem to get it straight.
> I need this number to be created using a query, as this query is a
> report's record source.
> Again, any help would be appreciated it.|||I'm tacking this very issue as well.
1. SQL Sever 2005 has symmetric and asymmetric encyption. Even tho its
slower, I testing asymmetric encryption. This way only the people that
should have access to the sSN will be able to decrypt it. The DBA's
wont even know the key.
2. On SQL Server 2000 see http://www.activecrypt.com/
This seemed to do the trick as well, but I have upgraded to 2005.
HTH
Rob

Monday, February 20, 2012

navigation on subtotal

I have a matrix and a subtotal footer summing up a group of numbers. Each row has a primary key. I use the primary key to drill-through another report through "Navigation".

Unfortunately, the generated subtotal column also have a link but it has a primary key of whatever the first row is, which shouldn't have a primary key. So I can drill-through the subtotal but it returns the wrong result.

I have not been able to override the subtotal to specify a new link with different paramters.

Anybody can help would be great!

Thanks.

In the place where you define the drillthrough action with its parameters, you have to use the InScope(...) function to determine if your are in a subtotal or not.

Please check the MSDN documentation about the InScope function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSCREATE/htm/rcr_creating_expressions_v1_0jmt.asp

With InScope you can determine the current scope of a matrix cell. Note: a matrix cell is "in scope" of column and row groupings, so you need at least two InScope function calls in the case where you have one dynamic row and one dynamic column grouping. E.g.
=iif(InScope("ColumnGroup1"), iif(InScope("RowGroup1"), "In Cell", "In Subtotal of RowGroup1"), iif(InScope("RowGroup1"), "In Subtotal of ColumnGroup1", "In Subtotal of entire matrix"))

-- Robert

|||Thanks for the suggestion. But I have two dynamic rows, one for SubTotal and one for Grand Total.

<DynamicRows>
<Grouping Name="GrandTotal">
....
<DynamicRows>
<Grouping Name="SubTotal">
...

I am having a hard time to link it to a correct report as it appears that GrandTotal is in scope of SubTotal. I am not sure to put that in the omit node as well.

If you can give me some instructions that would be great.

Thanks.

Jason
|||there are two subtotals, one is the rightmost column and the other is the bottom row. How can I disable the navigation for these two subtotals and still have navigation "In Cell"? Thanks if you can help or point out some resouces that I can go check.|||

Use the InScope function as described earlier in this thread.

For the cells, you would generate the desired hyperlink or drillthrough link. For subtotal scope you would just return Nothing (i.e. VB equivalent of null) in the IIF arguments. If a hyperlink expression evaluates to Nothing for a particular cell, the hyperlink action will be removed entirely.

-- Robert

|||

Hi, Robert,

The problem is still not solved. I still want the subtotal number shows on rightmost column and bottom row. The way that you told me, I will get empty column and row on the end. Let me try an example here:

co1 col2 col3 subtotal

row1 3 5 7 15

row2 1 2 3 6

subtotal 4 7 10 21

3, 5, 7, 1, 2, and 3, will have a hyperlink to jump to another report show detailed page, but I wanto 4, 7, 10, 15, 6, and 21 to show the number but disable the hyplerlinks.

Thanks!

Henry

|||

Yes, that should work fine.

For the matrix cell, you use an expression that shows calculates the value (e.g. =Sum(Fields!A.Value)).

Then, on that textbox add a navigation action. Only for the hyperlink expression you would use the complex expression using IIF calls and InScope calls.

Hope this clarifies it.

|||

Hi, Robert,

It works now. Thanks!

The key point: "sum(fields!a.value)" in Matrix cell and complex expression using iif and inscope in navigation action.

Henry

|||

hi,

can u please send me the query you used.

and please also gimme a explanation if possible.

Thanks in advance,

Vinu

navigation on subtotal

I have a matrix and a subtotal footer summing up a group of numbers. Each row has a primary key. I use the primary key to drill-through another report through "Navigation".

Unfortunately, the generated subtotal column also have a link but it has a primary key of whatever the first row is, which shouldn't have a primary key. So I can drill-through the subtotal but it returns the wrong result.

I have not been able to override the subtotal to specify a new link with different paramters.

Anybody can help would be great!

Thanks.

In the place where you define the drillthrough action with its parameters, you have to use the InScope(...) function to determine if your are in a subtotal or not.

Please check the MSDN documentation about the InScope function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSCREATE/htm/rcr_creating_expressions_v1_0jmt.asp

With InScope you can determine the current scope of a matrix cell. Note: a matrix cell is "in scope" of column and row groupings, so you need at least two InScope function calls in the case where you have one dynamic row and one dynamic column grouping. E.g.
=iif(InScope("ColumnGroup1"), iif(InScope("RowGroup1"), "In Cell", "In Subtotal of RowGroup1"), iif(InScope("RowGroup1"), "In Subtotal of ColumnGroup1", "In Subtotal of entire matrix"))

-- Robert

|||Thanks for the suggestion. But I have two dynamic rows, one for SubTotal and one for Grand Total.

<DynamicRows>
<Grouping Name="GrandTotal">
....
<DynamicRows>
<Grouping Name="SubTotal">
...

I am having a hard time to link it to a correct report as it appears that GrandTotal is in scope of SubTotal. I am not sure to put that in the omit node as well.

If you can give me some instructions that would be great.

Thanks.

Jason|||there are two subtotals, one is the rightmost column and the other is the bottom row. How can I disable the navigation for these two subtotals and still have navigation "In Cell"? Thanks if you can help or point out some resouces that I can go check.|||

Use the InScope function as described earlier in this thread.

For the cells, you would generate the desired hyperlink or drillthrough link. For subtotal scope you would just return Nothing (i.e. VB equivalent of null) in the IIF arguments. If a hyperlink expression evaluates to Nothing for a particular cell, the hyperlink action will be removed entirely.

-- Robert

|||

Hi, Robert,

The problem is still not solved. I still want the subtotal number shows on rightmost column and bottom row. The way that you told me, I will get empty column and row on the end. Let me try an example here:

co1 col2 col3 subtotal

row1 3 5 7 15

row2 1 2 3 6

subtotal 4 7 10 21

3, 5, 7, 1, 2, and 3, will have a hyperlink to jump to another report show detailed page, but I wanto 4, 7, 10, 15, 6, and 21 to show the number but disable the hyplerlinks.

Thanks!

Henry

|||

Yes, that should work fine.

For the matrix cell, you use an expression that shows calculates the value (e.g. =Sum(Fields!A.Value)).

Then, on that textbox add a navigation action. Only for the hyperlink expression you would use the complex expression using IIF calls and InScope calls.

Hope this clarifies it.

|||

Hi, Robert,

It works now. Thanks!

The key point: "sum(fields!a.value)" in Matrix cell and complex expression using iif and inscope in navigation action.

Henry

|||

hi,

can u please send me the query you used.

and please also gimme a explanation if possible.

Thanks in advance,

Vinu