Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Monday, March 19, 2012

Multiple Default Values of Parameter

I have a report parameter that will either have 1 value to pick from, or multiple values to pick from depending on who is logged in. I want to be able to set the default value to the first result that is returned in the dataset. Is there a simple way to do this without making a new dataset?Hi,

you either need a new dataset or a static value for the default property. You can′t use the dataset as a expression to get the first value of the dataset.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

Multiple DECLARE Sections ... why?

Is there any value to having multiple DECLARE sections within a single store
d
proc/statement block? I understand the value of multiple DECLARE sections
that are related to local variable within specific statement blocks.
However, in working with existing SP's, I run across the following on a
regular basis and would like to better understand if this structure provides
any value and/or cost to the proc's effeciency.
Thanks in advance for your insight/feedback.
Example:
CREATE PROC test
AS
DECLARE
@.var1 int,
@.var2 int
DECLARE
@.text1 varchar(8),
@.text2 varchar(8)It makes no difference. SQL is interpreted, so this won't make any
difference at all to the execution of the SP.
It looks like it was done to aid reading the code, all variables of the same
type declare together.
Regards
Colin Dawson
www.cjdawson.com
"Tom B." <TomB@.discussions.microsoft.com> wrote in message
news:74FD5973-B982-4C06-92F9-3DEAB4879109@.microsoft.com...
> Is there any value to having multiple DECLARE sections within a single
> stored
> proc/statement block? I understand the value of multiple DECLARE sections
> that are related to local variable within specific statement blocks.
> However, in working with existing SP's, I run across the following on a
> regular basis and would like to better understand if this structure
> provides
> any value and/or cost to the proc's effeciency.
> Thanks in advance for your insight/feedback.
> Example:
> CREATE PROC test
> AS
> DECLARE
> @.var1 int,
> @.var2 int
> DECLARE
> @.text1 varchar(8),
> @.text2 varchar(8)
>|||Sorry for any confusion, but the example was just that ... a basic
representation of the code that I've seen (actual code doesn't appear to hav
e
much rhyme or reason to the variable groupings). As for its value with
making the code more user friendly to read ... that makes perfect sense.
Thanks for the quick feedback!
"Tom B." wrote:

> Is there any value to having multiple DECLARE sections within a single sto
red
> proc/statement block? I understand the value of multiple DECLARE sections
> that are related to local variable within specific statement blocks.
> However, in working with existing SP's, I run across the following on a
> regular basis and would like to better understand if this structure provid
es
> any value and/or cost to the proc's effeciency.
> Thanks in advance for your insight/feedback.
> Example:
> CREATE PROC test
> AS
> DECLARE
> @.var1 int,
> @.var2 int
> DECLARE
> @.text1 varchar(8),
> @.text2 varchar(8)
>

Multiple datasets in one report?

I am trying to create a report that runs four queries.
If I use:
=(Fields!LongValueName.Value, "MTReg") I get:
c:\documents and settings\me\my documents\visual studio
projects\registrations\regVsAct.rdl The value expression
for the textbox 'LongValueName' contains an error:
[BC30198] ')' expected.
If I change it to =(Fields!MTReg.LongValueName.Value)
I get this:
c:\documents and settings\me\my documents\visual studio
projects\registrations\regVsAct.rdl The value expression
for the textbox 'LongValueName' refers to the
field 'MTReg'. Report item expressions can only refer to
fields within the current data set scope or, if inside an
aggregate, the specified data set scope.
Is this possible or am I just messing up the syntax?Looks like you are trying to refer to the field outside of any data regions.
You can change the expression to =First(Fields!LongValueName.Value,
"MTReg").
Fang Wang (MSFT)
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"bmurtha" <bmurtha@.corp.sms.ac> wrote in message
news:363c01c471d2$063f5060$a401280a@.phx.gbl...
> I am trying to create a report that runs four queries.
> If I use:
> =(Fields!LongValueName.Value, "MTReg") I get:
> c:\documents and settings\me\my documents\visual studio
> projects\registrations\regVsAct.rdl The value expression
> for the textbox 'LongValueName' contains an error:
> [BC30198] ')' expected.
> If I change it to =(Fields!MTReg.LongValueName.Value)
> I get this:
> c:\documents and settings\me\my documents\visual studio
> projects\registrations\regVsAct.rdl The value expression
> for the textbox 'LongValueName' refers to the
> field 'MTReg'. Report item expressions can only refer to
> fields within the current data set scope or, if inside an
> aggregate, the specified data set scope.
> Is this possible or am I just messing up the syntax?
>|||Thanks Fang,
Actually, as it turned out, I was trying to call a
dataset , say b, when I was using a table that was bound
to databset a. I didn't get that what I'm really dealing
with is a datagrid and that it has a bound connections.
This is what happens when you start depending on the GUI
rather then thinking for yourself. Also it didn't occur to
me that iterators for each of these datasets would be
completely different.
Regards,
Bryan
>--Original Message--
>Looks like you are trying to refer to the field outside
of any data regions.
>You can change the expression to =First(Fields!
LongValueName.Value,
>"MTReg").
>Fang Wang (MSFT)
>Microsoft SQL Server Reporting Services
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>"bmurtha" <bmurtha@.corp.sms.ac> wrote in message
>news:363c01c471d2$063f5060$a401280a@.phx.gbl...
>> I am trying to create a report that runs four queries.
>> If I use:
>> =(Fields!LongValueName.Value, "MTReg") I get:
>> c:\documents and settings\me\my documents\visual studio
>> projects\registrations\regVsAct.rdl The value expression
>> for the textbox 'LongValueName' contains an error:
>> [BC30198] ')' expected.
>> If I change it to =(Fields!MTReg.LongValueName.Value)
>> I get this:
>> c:\documents and settings\me\my documents\visual studio
>> projects\registrations\regVsAct.rdl The value expression
>> for the textbox 'LongValueName' refers to the
>> field 'MTReg'. Report item expressions can only refer
to
>> fields within the current data set scope or, if inside
an
>> aggregate, the specified data set scope.
>> Is this possible or am I just messing up the syntax?
>>
>
>.
>

Wednesday, March 7, 2012

Multiple columns as the pivot key

Hello,

Here is a sample of the data that I am trying to pivot;

rec_id sequence field_name value

1 1 cat_nbr Granrier

1 1 cat_page pg 21

1 2 cat_nbr H&S

1 2 cat_page pg234

2 1 cat_nbr Ford

2 1 cat_page pg5

I need to pivot on rec_id and sequence to get an output like this:

rec_id sequence cat_nbr cat_page

1 1 Granrier pg21

1 2 H&S pg234

2 1 Ford pg5

All I seem to be able to get thoug is this:

rec_id sequence cat_nbr cat_page

1 1 Granrier

1 1 pg21

1 2 H&S

1 2 pg234

2 1 Ford pg5

It seems to me that the pivot transform can only pivot around one key value column. What am I missing?

Thanks.

This is an easy SQL statement -- no need for SSIS: (I'm assuming your table is named "table" -- change accordingly)

SELECT a.rec_id, a.sequence, a.cat_nbr, b.cat_page
FROM

(SELECT rec_id, sequence, value as cat_nbr
FROM table
WHERE field_name = 'cat_nbr') a,

(SELECT rec_id, sequence, value as cat_page
FROM table
WHERE field_name = 'cat_page') b

WHERE a.rec_id = b.rec_id
AND a.sequence = b.sequence|||you can also use a derived column and combine the various elements of the compound key into a single key field. i.e., rec_id + "_" + sequence.|||I was having the same problem. Add a Sort transform before the pivot in which you sort by the key columns. That should eliminate the duplicates.

multiple column values into a single value

hi all,
I am trying to take all the values from a single varchar column and to inset
them into a variable so that they are seperated with the '-' sign.
I am trying to avoid cursors.
by the way- all the rows have a column with the same value in the table
for example:
create table test (col1 int, col2 varchar(20))
insert test values(1,'aaa')
insert test values(1,'bbb')
insert test values(1,'ccc')
the result sould look like this 'aaa-bbb-ccc'
thaks,
alonA cursor/iterative solution is best suited for this.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"alon" <alon@.discussions.microsoft.com> wrote in message
news:BEB95AAB-5C04-4466-B940-B00AAAAE0DE3@.microsoft.com...
> hi all,
> I am trying to take all the values from a single varchar column and to
> inset
> them into a variable so that they are seperated with the '-' sign.
> I am trying to avoid cursors.
> by the way- all the rows have a column with the same value in the table
> for example:
> create table test (col1 int, col2 varchar(20))
> insert test values(1,'aaa')
> insert test values(1,'bbb')
> insert test values(1,'ccc')
> the result sould look like this 'aaa-bbb-ccc'
> thaks,
> alon|||create table #test (col1 int, col2 varchar(20))
insert #test values(1,'aaa')
insert #test values(1,'bbb')
insert #test values(1,'ccc')
DECLARE @.concat VARCHAR(100)
SET @.concat=''
SELECT
CASE WHEN @.concat='' THEN '' ELSE '-' END + col2
FROM #test
DROP TABLE #Test
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"alon" <alon@.discussions.microsoft.com> wrote in message
news:BEB95AAB-5C04-4466-B940-B00AAAAE0DE3@.microsoft.com...
> hi all,
> I am trying to take all the values from a single varchar column and to
> inset
> them into a variable so that they are seperated with the '-' sign.
> I am trying to avoid cursors.
> by the way- all the rows have a column with the same value in the table
> for example:
> create table test (col1 int, col2 varchar(20))
> insert test values(1,'aaa')
> insert test values(1,'bbb')
> insert test values(1,'ccc')
> the result sould look like this 'aaa-bbb-ccc'
> thaks,
> alon|||Maybe this can help:
http://milambda.blogspot.com/2005/0...s-as-array.html
Of course you'll need to change it to meet your specific needs.
ML|||So you want to destroy First Normal Form (1NF) with a proprieetary
kludge? In a tiered archtiecture, display is done inthe front end and
not in the database. This is far more basic than just SQL programming.|||http://www.aspfaq.com/2529
"alon" <alon@.discussions.microsoft.com> wrote in message
news:BEB95AAB-5C04-4466-B940-B00AAAAE0DE3@.microsoft.com...
> hi all,
> I am trying to take all the values from a single varchar column and to
> inset
> them into a variable so that they are seperated with the '-' sign.
> I am trying to avoid cursors.
> by the way- all the rows have a column with the same value in the table
> for example:
> create table test (col1 int, col2 varchar(20))
> insert test values(1,'aaa')
> insert test values(1,'bbb')
> insert test values(1,'ccc')
> the result sould look like this 'aaa-bbb-ccc'
> thaks,
> alon