Showing posts with label pivot. Show all posts
Showing posts with label pivot. Show all posts

Thursday, March 22, 2012

Easier way of building pivot tables in MS SQL Server

Dear All

I am very new to MS SQL Server and I am wondering is there some tool
which would allow me to build pivot tables in SQL more easily. At the
moment writing a query can be quite challenging and difficult.

Is there any software which allows you to do it more intuitively and
gives you some visual feedback about query you are building?

I would be very grateful for any help with this.

wujtehacjuszWhat version of SQL Server?

SQL Server 2005 has the PIVOT command.

On Jul 10, 5:19 am, wujtehacjusz <wujtehacj...@.gmail.comwrote:

Quote:

Originally Posted by

Dear All
>
I am very new to MS SQL Server and I am wondering is there some tool
which would allow me to build pivot tables in SQL more easily. At the
moment writing a query can be quite challenging and difficult.
>
Is there any software which allows you to do it more intuitively and
gives you some visual feedback about query you are building?
>
I would be very grateful for any help with this.
>
wujtehacjusz

|||For SQL 2000, check out http://www.rac4sql.net/
--
Hope this helps.

Dan Guzman
SQL Server MVP

"wujtehacjusz" <wujtehacjusz@.gmail.comwrote in message
news:1184059198.208520.109590@.q75g2000hsh.googlegr oups.com...

Quote:

Originally Posted by

Dear All
>
I am very new to MS SQL Server and I am wondering is there some tool
which would allow me to build pivot tables in SQL more easily. At the
moment writing a query can be quite challenging and difficult.
>
Is there any software which allows you to do it more intuitively and
gives you some visual feedback about query you are building?
>
I would be very grateful for any help with this.
>
wujtehacjusz
>

Wednesday, March 7, 2012

Dynamically change column width in matrix

Hi, All,
I am designing a report which will use matrix to show a pivot table. Matrix
in reporting service is wonderful for showing a pivot table. However, when
it is used to show the detail information based on column group, I cannot
change the column width dynamically. The width for columns has to be
specified by fixed number, which means the whole width of that matix cannot
be fixed. The more dynamic columns it has, the wider it will be. Is there
any way I could specify it in percentage or something else I could do so I
could fix the width of matrix which will has variable columns in it?
Thank for any recommendations.
HenrySupport for dynamic column sizing is on the wish list for inclusion in a
future release.
--
Bruce Johnson [MSFT]
Microsoft SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Henry" <wang_yuhang@.hotmail.com> wrote in message
news:evIba1blEHA.2820@.TK2MSFTNGP15.phx.gbl...
> Hi, All,
> I am designing a report which will use matrix to show a pivot table.
Matrix
> in reporting service is wonderful for showing a pivot table. However, when
> it is used to show the detail information based on column group, I cannot
> change the column width dynamically. The width for columns has to be
> specified by fixed number, which means the whole width of that matix
cannot
> be fixed. The more dynamic columns it has, the wider it will be. Is there
> any way I could specify it in percentage or something else I could do so I
> could fix the width of matrix which will has variable columns in it?
> Thank for any recommendations.
> Henry
>
>|||Thanks, Bruce.
I am looking forward to the next version...
Henry
"Bruce Johnson [MSFT]" <brucejoh@.online.microsoft.com> wrote in message
news:ePr$TXclEHA.2884@.TK2MSFTNGP09.phx.gbl...
> Support for dynamic column sizing is on the wish list for inclusion in a
> future release.
> --
> Bruce Johnson [MSFT]
> Microsoft SQL Server Reporting Services
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> "Henry" <wang_yuhang@.hotmail.com> wrote in message
> news:evIba1blEHA.2820@.TK2MSFTNGP15.phx.gbl...
>> Hi, All,
>> I am designing a report which will use matrix to show a pivot table.
> Matrix
>> in reporting service is wonderful for showing a pivot table. However,
>> when
>> it is used to show the detail information based on column group, I cannot
>> change the column width dynamically. The width for columns has to be
>> specified by fixed number, which means the whole width of that matix
> cannot
>> be fixed. The more dynamic columns it has, the wider it will be. Is there
>> any way I could specify it in percentage or something else I could do so
>> I
>> could fix the width of matrix which will has variable columns in it?
>> Thank for any recommendations.
>> Henry
>>
>

Sunday, February 19, 2012

Dynamic SQL statements over 4000 chars

Hi, All,
I am using SQL Server 2000.
I want to dynamically build a SQL statement for pivot query, which come out
more than the character limits for variable and sp_executesql..
What I need is: a query to return all security_level for all User_Id for all
screen_id. We have more than 280 user accounts in AcctUsers table. The
Output format need to be:
Screen User1 User2 User3 .....
Window1 0 1 2
Window2 3 2 0
I used cursor to get user_ids from AcctUsers table, then dynamically build
the SQL statment based on the User_ID. It works fine for up to about 40
user_ids. But it out off the chararter limit for variable nverachar and
sp_executesql. The way that I choose dynamical SQL because the business user
may add new user_id to AcctUsers table and then run a report, which will
call this query.
Can anyone help me?
Thanks.
Perayu
Here are the DDL:
CREATE TABLE [dbo].[AcctUsers] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[first_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[middle_initial] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[last_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Security] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[screen_id] [smallint] NOT NULL ,
[security_level] [smallint] NOT NULL
) ON [PRIMARY]
GOHi!
Do please check this: http://www.sommarskog.se/dynamic_sql.html#use-which.
I would suggest you to read the complete article.
Dejan Sarka, SQL Server MVP
Mentor, www.SolidQualityLearning.com
Anything written in this message represents solely the point of view of the
sender.
This message does not imply endorsement from Solid Quality Learning, and it
does not represent the point of view of Solid Quality Learning or any other
person, company or institution mentioned in this message
"Perayu" <yu.he@.state.mn.us.Remove4Replay> wrote in message
news:eL2e9rTPGHA.2628@.TK2MSFTNGP15.phx.gbl...
> Hi, All,
> I am using SQL Server 2000.
> I want to dynamically build a SQL statement for pivot query, which come
> out more than the character limits for variable and sp_executesql..
> What I need is: a query to return all security_level for all User_Id for
> all screen_id. We have more than 280 user accounts in AcctUsers table. The
> Output format need to be:
> Screen User1 User2 User3 .....
> Window1 0 1 2
> Window2 3 2 0
> I used cursor to get user_ids from AcctUsers table, then dynamically build
> the SQL statment based on the User_ID. It works fine for up to about 40
> user_ids. But it out off the chararter limit for variable nverachar and
> sp_executesql. The way that I choose dynamical SQL because the business
> user may add new user_id to AcctUsers table and then run a report, which
> will call this query.
> Can anyone help me?
> Thanks.
> Perayu
> Here are the DDL:
> CREATE TABLE [dbo].[AcctUsers] (
> [ID] [int] IDENTITY (1, 1) NOT NULL ,
> [user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [first_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [middle_initial] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [last_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Security] (
> [ID] [int] IDENTITY (1, 1) NOT NULL ,
> [user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [screen_id] [smallint] NOT NULL ,
> [security_level] [smallint] NOT NULL
> ) ON [PRIMARY]
> GO
>|||Great article!
Here is the trick that I will try, nesting EXEC:
DECLARE @.sql1 nvarchar(4000),
@.sql2 nvarchar(4000),
@.state char(2)
SELECT @.state = 'CA'
SELECT @.sql1 = N'SELECT COUNT(*)'
SELECT @.sql2 = N'FROM authors WHERE state = @.state'
EXEC('EXEC sp_executesql N''' + @.sql1 + @.sql2 + ''',
N''@.state char(2)'',
@.state = ''' + @.state + '''')
Thanks for your help!
Perayu
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in
message news:Oqh49AUPGHA.1760@.TK2MSFTNGP10.phx.gbl...
> Hi!
> Do please check this: http://www.sommarskog.se/dynamic_sql.html#use-which.
> I would suggest you to read the complete article.
> --
> Dejan Sarka, SQL Server MVP
> Mentor, www.SolidQualityLearning.com
> Anything written in this message represents solely the point of view of
> the sender.
> This message does not imply endorsement from Solid Quality Learning, and
> it does not represent the point of view of Solid Quality Learning or any
> other person, company or institution mentioned in this message
> "Perayu" <yu.he@.state.mn.us.Remove4Replay> wrote in message
> news:eL2e9rTPGHA.2628@.TK2MSFTNGP15.phx.gbl...
>|||If unicode is not a requirement, you can store 8000 chars in varchar. The
unicode nvarchar will only store 4000.
"Perayu" <yu.he@.state.mn.us.Remove4Replay> wrote in message
news:eL2e9rTPGHA.2628@.TK2MSFTNGP15.phx.gbl...
> Hi, All,
> I am using SQL Server 2000.
> I want to dynamically build a SQL statement for pivot query, which come
> out more than the character limits for variable and sp_executesql..
> What I need is: a query to return all security_level for all User_Id for
> all screen_id. We have more than 280 user accounts in AcctUsers table. The
> Output format need to be:
> Screen User1 User2 User3 .....
> Window1 0 1 2
> Window2 3 2 0
> I used cursor to get user_ids from AcctUsers table, then dynamically build
> the SQL statment based on the User_ID. It works fine for up to about 40
> user_ids. But it out off the chararter limit for variable nverachar and
> sp_executesql. The way that I choose dynamical SQL because the business
> user may add new user_id to AcctUsers table and then run a report, which
> will call this query.
> Can anyone help me?
> Thanks.
> Perayu
> Here are the DDL:
> CREATE TABLE [dbo].[AcctUsers] (
> [ID] [int] IDENTITY (1, 1) NOT NULL ,
> [user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [first_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [middle_initial] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [last_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ) ON [PRIMARY]
> GO
> CREATE TABLE [dbo].[Security] (
> [ID] [int] IDENTITY (1, 1) NOT NULL ,
> [user_id] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [screen_id] [smallint] NOT NULL ,
> [security_level] [smallint] NOT NULL
> ) ON [PRIMARY]
> GO
>