Sunday, April 14, 2013

[T-SQL] Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL)

[T-SQL] Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL)


Passing Multiple Values As Parameters to get Multiple Columns with Comma Seperation(MSSQL)

Posted: 04 Apr 2013 10:06 PM PDT

Create procedure temp(@MID smallint)asBeginselect TranID,[MonthValue]=(CASE WHEN @MID=1 THEN Jan WHEN @MID=2 THEN Feb WHEN @MID=3 THEN Mar WHEN @MID=4 THEN Apr WHEN @MID=5 THEN May WHEN @MID=6 THEN Jun WHEN @MID=7 THEN Jul END) FROM TblTran as M where TranID=1 and M.Month = @MIDendThis is a stored procedure with a parameter @MID that i'm using to generate a report using SSRS.If a single value is passed to the parameter it works fine.For example-Transaction Table[b][u]TranID | Apr | May | Jun | Jul [/u][/b] 1 | 50 | 30 | 11 | 30 2 | 51 | 39 | 100 | 30if i execute with[b]Exec 4[/b]the result is what i expect[b][u]TranID | MonthValue [/u] [/b] 1 | 50 **-- ie Aprils value**But I need to pass multiple values to the parameterlike[b]exec 4,5,6[/b]and desired result should be[u][b]TranID | MonthValue [/b] [/u] 1 | 50,30,11 ***-->Comma Separated values of columns how can i acheive result like this??

Query help needed - Like a Pivot with generic headings?

Posted: 13 Apr 2013 06:45 AM PDT

[code="sql"]CREATE TABLE [dbo].[mike_inventory]( [itemid] [int] NULL, [location] [varchar](50) NULL[/code][code="sql"]insert into mike_inventory values (10131,'Row A')insert into mike_inventory values (10131,'Row B')insert into mike_inventory values (10132,'Row B')insert into mike_inventory values (10132,'Row C')insert into mike_inventory values (10133,'Row A')insert into mike_inventory values (10133,'Row D')insert into mike_inventory values (10134,'Row A')insert into mike_inventory values (10134,'Row E')[/code]I want my output to look like this[code="sql"]Itemid Location1 Location2 Location3--------------------------------------------------------------------------------------------10131 ROW A ROW B 10132 ROW B ROW C 10133 ROW A ROW D10134 ROW A ROW E[/code]Is this possible?

Urgent Query help needed- calculate one field based on other field in SELECT statment

Posted: 13 Apr 2013 08:55 AM PDT

Hi Friends,I have reporting TSQL query- in this query within the select statement I have 2 fields 1) Age (working Days) and 2) Age Group(Working days).the requirement demands that based on the first Select field - Age(working Days) I, display one of these selections: 0 - 2930 - 5960 - 8990 - 119120 +for the Second SELECT list field Age Group(Working Days)Note- the data Type for both is Varchar.thanksDhananjay

No comments:

Post a Comment

Search This Blog