Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

Monday, March 26, 2012

MultiRow select to SingleRow output?

Here is what I want to do.

I have a customer table with say id, firstname, lastname. I also have another table called phone number that contains multiple phone numbers based on the customer id (id, customerid, phonenumber).

Ok I want to output a record like this

firstname, lastname, phone1, phone2, phone3

I need one record per customer with as many phone numbers as they may have, I could always limit the numbers to 3 or better yet return a null if there are less then the predefined number of phone numbers.

If I try a simple join I get multiline output which is no good for me.

SELECT firstname, lastname, phonenumber
FROM customer, phone
WHERE phone.customerid = customer.id

Thanks.---------------
create function dbo.PhoneString(@.customerid int)
returns varchar(500)
as
begin
declare @.PhoneString varchar(500)

set @.PhoneString = ''

select @.PhoneString = @.PhoneString + phonenumber + ', '
from PhoneNumberTable
where customerid = @.customerid

set @.PhoneString = left(@.PhonesString, len(@.PhoneString)-1)

return @.PhoneString
end
---------------
select firstname, lastname, dbo.PhoneString(ID) from customers

Friday, March 9, 2012

Multiple Table Combination

I would like to create a query that would generate the output table, but I'm not sure where to start.

[USER TABLE]

userID fName lName
1 Joe Smith
2 Mike Brown

[CATEGORY TABLE]

categoryID title
1 category1
2 category2
3 category3

[USERCATEGORy TABLE]

userID categoryID
1 1
1 3
2 2
2 3

[OUTPUT TABLE]
(comma seperate rows

fName lName category1 category2 category3
Joe,Smith,x, ,x
Mike,Brown, ,x,xThis is a classic cross-tab query. There is a generic solution, and there are database engine specific solutions. The generic solution is a lot more work, and it is vulnerable to some kinds of data errors.

Can you give us a bit more background so we can help you out?

-PatP|||The rdbms is ms sql 2000. I was debating wether to post it here or in that category. It will lead to an output as an excel file, that is why I want the x's in the category, but for now i'm just interesting the sql to generate this. If a sql solution is not advisable I welcome pointers in t-sql that might help me with this.|||Try doing a search for cross-tab in the SQL Server forum. I've answered this type of question at least a dozen times there, you should be able to find a decent hit or three!

-PatP|||Books On Line has an excellent explanation and example of Crosstab queries. Look it up.

Saturday, February 25, 2012

Multiple selects on PArameter drop down

I have a parameter dropdown as USERID.

I want a functionality that the user can selct multiple userid's to show more than one record as output for comparison purpose.

How can i achieve this multiple select (i.e cntrl+click) within parameter dropdown.

Thanks,

Kiran.

In the report parameters window, check the 'Multi-value' box on your UserID parameter. In the available values section, you can type the possible values, or query the database to get the list.

You will also need to take the multiple values into account on your data query, you'll need to use 'IN' instead of '=' on your where clause for UserID.

This will show on the report as a drop down, where the user can check which values to run the report with.

Hope this helps,

Jarret

|||

Thank you Jarret.

I cannot find teh checkbox for 'multi-value'' allowed . I am using reporting services 2000 on visual Studios.NET 2003 SQL Server 2000.

Is this an issue for me only. I have the checkboxes for allow null values and allow blank values for the userid parameter.

thanks.

|||

Sorry, I had assumed that you were running RS 2005. In Reporting Services 2000, a report parameter can only be defined to allow the user to enter a single value.

Jarret

|||

Thanks Jarret,

Is there a wor around that I should be trying.

Appreciate the time.

|||

Hmmm...

You could try changing the parameter type to string and make your data query use 'IN', then have the user type a comma delimited list. I haven't tried it, but you might be able to get it to work.

Jarret

|||Did this work for you?|||

This did not work for me. I shifted to 2005 and implemented it.

Thanks

Multiple selects on PArameter drop down

I have a parameter dropdown as USERID.

I want a functionality that the user can selct multiple userid's to show more than one record as output for comparison purpose.

How can i achieve this multiple select (i.e cntrl+click) within parameter dropdown.

Thanks,

Kiran.

In the report parameters window, check the 'Multi-value' box on your UserID parameter. In the available values section, you can type the possible values, or query the database to get the list.

You will also need to take the multiple values into account on your data query, you'll need to use 'IN' instead of '=' on your where clause for UserID.

This will show on the report as a drop down, where the user can check which values to run the report with.

Hope this helps,

Jarret

|||

Thank you Jarret.

I cannot find teh checkbox for 'multi-value'' allowed . I am using reporting services 2000 on visual Studios.NET 2003 SQL Server 2000.

Is this an issue for me only. I have the checkboxes for allow null values and allow blank values for the userid parameter.

thanks.

|||

Sorry, I had assumed that you were running RS 2005. In Reporting Services 2000, a report parameter can only be defined to allow the user to enter a single value.

Jarret

|||

Thanks Jarret,

Is there a wor around that I should be trying.

Appreciate the time.

|||

Hmmm...

You could try changing the parameter type to string and make your data query use 'IN', then have the user type a comma delimited list. I haven't tried it, but you might be able to get it to work.

Jarret

|||Did this work for you?|||

This did not work for me. I shifted to 2005 and implemented it.

Thanks

Multiple selects on PArameter drop down

I have a parameter dropdown as USERID.

I want a functionality that the user can selct multiple userid's to show more than one record as output for comparison purpose.

How can i achieve this multiple select (i.e cntrl+click) within parameter dropdown.

Thanks,

Kiran.

In the report parameters window, check the 'Multi-value' box on your UserID parameter. In the available values section, you can type the possible values, or query the database to get the list.

You will also need to take the multiple values into account on your data query, you'll need to use 'IN' instead of '=' on your where clause for UserID.

This will show on the report as a drop down, where the user can check which values to run the report with.

Hope this helps,

Jarret

|||

Thank you Jarret.

I cannot find teh checkbox for 'multi-value'' allowed . I am using reporting services 2000 on visual Studios.NET 2003 SQL Server 2000.

Is this an issue for me only. I have the checkboxes for allow null values and allow blank values for the userid parameter.

thanks.

|||

Sorry, I had assumed that you were running RS 2005. In Reporting Services 2000, a report parameter can only be defined to allow the user to enter a single value.

Jarret

|||

Thanks Jarret,

Is there a wor around that I should be trying.

Appreciate the time.

|||

Hmmm...

You could try changing the parameter type to string and make your data query use 'IN', then have the user type a comma delimited list. I haven't tried it, but you might be able to get it to work.

Jarret

|||Did this work for you?|||

This did not work for me. I shifted to 2005 and implemented it.

Thanks