Showing posts with label level. Show all posts
Showing posts with label level. Show all posts

Friday, March 30, 2012

Please help Invalid Cloumn Name

Hi,
Here is my SP
I need to run this as this
ConFirmOrders_SP 'SVR,UCC' this is giving me
Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'UCC'.
Server: Msg 207, Level 16, State 1, Line 1
Invalid column name 'SVR'.
ALTER Procedure ConfirmOrders_sp
(
@.StrType Varchar(100)
)
As
BEGIN
SET NOCOUNT ON
Create table #Confirm
(
ShipName Varchar(80),
Reference Varchar(60),
ReqNo int,
CorpName varchar(255),
ReqDate datetime,
RptType nVarchar(24)
)
Declare @.SQL varchar(5000)
Insert into #Confirm(ShipName,Reference,ReqNo,CorpNa
me,ReqDate,RptType)
SELECT Sh.ShiptoName , Req.RefNo , Req.Reqno ,
Case Sm.ItemGroup
When 'UCC' Then Req.Debtor
When 'SVR' Then Req.Respecting
When 'SAT' Then Req.CorpName
When 'SRO' Then Req.CorpName
When 'TRO' Then Req.CorpName
When 'REG' Then Req.CorpName
End As [Name],Req.Reqdate,SM.ItemGroup As [Req Type]
FROM dbo.tblArShipTo Sh INNER JOIN
dbo.tblCorpRpt Req ON Sh.CustId = Req.CustId INNER JOIN dbo.tblSmItem SM
ON Req.ReqType = SM.ItemCode
WHERE Req.Reqstatus ='W' AND Sh.ShiptoId ='MAIL'
Order By Req.Reqno
Set @.SQL=
'Select ShipName AS [Cust Name],Reference,ReqNo,CorpName AS [Name],
ReqDate AS [Req Date],RptType AS [Rpt Type] from #Confirm WHERE Rpttype IN
(' + @.StrType + ')'
Exec(@.SQL)
ENDSVR and UCC are individual strings so they both need to be quoted
individually. Change your call to something like this:
ConFirmOrders_SP '''SVR'',''UCC'''
You'll need to double check that I have the quotes done correctly, but you
should get the idea.
--Brian
(Please reply to the newsgroups only.)
"Dib" <dNOSPAMshahene@.conNOSPAMsoftware.com> wrote in message
news:uRETsQ%23rFHA.2212@.TK2MSFTNGP15.phx.gbl...
> Hi,
> Here is my SP
> I need to run this as this
> ConFirmOrders_SP 'SVR,UCC' this is giving me
> Server: Msg 207, Level 16, State 3, Line 1
> Invalid column name 'UCC'.
> Server: Msg 207, Level 16, State 1, Line 1
> Invalid column name 'SVR'.
>
> ALTER Procedure ConfirmOrders_sp
> (
> @.StrType Varchar(100)
> )
> As
> BEGIN
> SET NOCOUNT ON
> Create table #Confirm
> (
> ShipName Varchar(80),
> Reference Varchar(60),
> ReqNo int,
> CorpName varchar(255),
> ReqDate datetime,
> RptType nVarchar(24)
> )
> Declare @.SQL varchar(5000)
> Insert into #Confirm(ShipName,Reference,ReqNo,CorpNa
me,ReqDate,RptType)
> SELECT Sh.ShiptoName , Req.RefNo , Req.Reqno ,
> Case Sm.ItemGroup
> When 'UCC' Then Req.Debtor
> When 'SVR' Then Req.Respecting
> When 'SAT' Then Req.CorpName
> When 'SRO' Then Req.CorpName
> When 'TRO' Then Req.CorpName
> When 'REG' Then Req.CorpName
> End As [Name],Req.Reqdate,SM.ItemGroup As [Req Type]
> FROM dbo.tblArShipTo Sh INNER JOIN
> dbo.tblCorpRpt Req ON Sh.CustId = Req.CustId INNER JOIN dbo.tblSmItem SM
> ON Req.ReqType = SM.ItemCode
> WHERE Req.Reqstatus ='W' AND Sh.ShiptoId ='MAIL'
> Order By Req.Reqno
> Set @.SQL=
> 'Select ShipName AS [Cust Name],Reference,ReqNo,CorpName AS [Name],
> ReqDate AS [Req Date],RptType AS [Rpt Type] from #Confirm WHERE Rpttype IN
> (' + @.StrType + ')'
>
> Exec(@.SQL)
> END
>|||Thanks
Dib
"Brian Lawton" <brian.k.lawton@.redtailcr.com> wrote in message
news:OWca8W%23rFHA.908@.tk2msftngp13.phx.gbl...
> SVR and UCC are individual strings so they both need to be quoted
> individually. Change your call to something like this:
> ConFirmOrders_SP '''SVR'',''UCC'''
> You'll need to double check that I have the quotes done correctly, but you
> should get the idea.
> --
> --Brian
> (Please reply to the newsgroups only.)
>
> "Dib" <dNOSPAMshahene@.conNOSPAMsoftware.com> wrote in message
> news:uRETsQ%23rFHA.2212@.TK2MSFTNGP15.phx.gbl...
>sql

Wednesday, March 21, 2012

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
Chip
Hi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip
|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a[vbcol=seagreen]
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
Production[vbcol=seagreen]
have[vbcol=seagreen]
and[vbcol=seagreen]
server[vbcol=seagreen]
maintenance[vbcol=seagreen]
for[vbcol=seagreen]
8K
>
>.
>
|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Servers
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...[vbcol=seagreen]
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> and user databases.
> Moving SQL Server
> databases to new server.
> permissions..If you are
> lost.
> trace flag "-T3608"
> use ALTER DATBASE ..
> allocated to hold a
> Production
> have
> and
> server
> maintenance
> for
> 8K
|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...[vbcol=seagreen]
databases[vbcol=seagreen]
backups of[vbcol=seagreen]
SQL[vbcol=seagreen]
msdb.ldf[vbcol=seagreen]
work[vbcol=seagreen]
Default[vbcol=seagreen]
of
>
>.
>
|||That should be in the articles. You can restore MSDB as well as master. For master, you need to be in single
user mode in order to do a restore.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a001280a@.phx.gbl...[vbcol=seagreen]
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> Detach/Attach
> Between SQL Servers
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> databases
> backups of
> SQL
> msdb.ldf
> work
> Default
> of

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
ChipHi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
>> Hi Group,
>> For some reasons I have to pull the SQL Server
Production
>> server out of network and reinstall from OS level. I
have
>> few queries about Backing up the SQL server Databases
and
>> choosing cluster size.
>> 1. Do I need to Backup/detach the Master,MSDB databases
>> along with User database to restore again when SQL
server
>> is installed again freshly?. MSDB just has two
maintenance
>> plans running.I fell that I can just take the backups of
>> User databases as I have to restore them on fresh
>> installation.
>> 2. I am creating three arrays on this server
>> C: RAID1 Array ( OS) - Array1
>> D: RAID1 (SQL Tran logs files)- Array2
>> D: RAID5E ( SQL Data files) - Array3
>> While installing SQLServer I will choose Array3 for SQL
>> system databases. How do i move the master.ldf msdb.ldf
>> model.ldf temp.ldf to Array2 ? does detach/attach work
for
>> system databses?
>> 3. I am choosing 8KB Cluster on NTFS instead of Default
>> 4KB cluster, does this help in enhancing the access of
8K
>> SQL database pages in terms of I/O?
>> 4. Are there any patches/fixes released after
>> SQLServer2000 Service Pack 3a?
>> OS Windows 2000 Server SP4
>> SQL Server 2000 Standard Edition
>> IBM x250 dual PIII Xeon 700MHz
>> 4GB RAM
>> 18GB for OS on server
>> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
>> Thanks for your patience
>> Regards
>> Chip
>
>.
>|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Servers
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> >--Original Message--
> >Hi,
> >
> >1. This link details you the steps to move the system
> and user databases.
> > http://www.support.microsoft.com/?id=224071
> Moving SQL Server
> >Databases to a New Location with Detach/Attach
> > It is always good to move the Master and MSDB
> databases to new server.
> >But it is a must that you should move master database
> > since it stores Server config, Logins
> permissions..If you are
> >notloading master all the database users chanin will be
> lost.
> >
> >2. For Master database after starting sql server using
> trace flag "-T3608"
> >and use sp_detach_db and then copy to new drive and use
> > sp_attach_db to attach Master database. For Tempdb
> use ALTER DATBASE ..
> >MODIFY FILE option. Both methodologies are detailed
> > in the above link
> >
> >3. This represent the smallest amount of disk space
> allocated to hold a
> >file.
> > I feel this might not reduce your I/O.
> >
> >
> >4. No, Sp3a is the latest service pack.
> >
> >Thanks
> >Hari
> >MCDBA
> >
> >
> >
> >"Chip" <Chipsin007@.yahoo.com> wrote in message
> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> >> Hi Group,
> >>
> >> For some reasons I have to pull the SQL Server
> Production
> >> server out of network and reinstall from OS level. I
> have
> >> few queries about Backing up the SQL server Databases
> and
> >> choosing cluster size.
> >>
> >> 1. Do I need to Backup/detach the Master,MSDB databases
> >> along with User database to restore again when SQL
> server
> >> is installed again freshly?. MSDB just has two
> maintenance
> >> plans running.I fell that I can just take the backups of
> >> User databases as I have to restore them on fresh
> >> installation.
> >>
> >> 2. I am creating three arrays on this server
> >> C: RAID1 Array ( OS) - Array1
> >> D: RAID1 (SQL Tran logs files)- Array2
> >> D: RAID5E ( SQL Data files) - Array3
> >>
> >> While installing SQLServer I will choose Array3 for SQL
> >> system databases. How do i move the master.ldf msdb.ldf
> >> model.ldf temp.ldf to Array2 ? does detach/attach work
> for
> >> system databses?
> >>
> >> 3. I am choosing 8KB Cluster on NTFS instead of Default
> >> 4KB cluster, does this help in enhancing the access of
> 8K
> >> SQL database pages in terms of I/O?
> >>
> >> 4. Are there any patches/fixes released after
> >> SQLServer2000 Service Pack 3a?
> >>
> >> OS Windows 2000 Server SP4
> >> SQL Server 2000 Standard Edition
> >> IBM x250 dual PIII Xeon 700MHz
> >> 4GB RAM
> >> 18GB for OS on server
> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> >>
> >> Thanks for your patience
> >>
> >> Regards
> >>
> >> Chip
> >
> >
> >.
> >|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
>> Hi Hari,
>> Thanks for the help! one more doubt.. When I install SQL
>> Server by default it will create Master,MSDB . How do i
>> get rid of them and attach the last backed up master
>> (.mdf,.ldf), MSDB(.mdf,.ldf).
>> I guess I have to login in singleuser mode, detach them,
>> overwrite with the backed up files then attach?
>> Please give me step by step ( you are always awesome in
>> dealing step by step)
>> Sincerely
>> Chip
>> >--Original Message--
>> >Hi,
>> >
>> >1. This link details you the steps to move the system
>> and user databases.
>> > http://www.support.microsoft.com/?id=224071
>> Moving SQL Server
>> >Databases to a New Location with Detach/Attach
>> > It is always good to move the Master and MSDB
>> databases to new server.
>> >But it is a must that you should move master database
>> > since it stores Server config, Logins
>> permissions..If you are
>> >notloading master all the database users chanin will be
>> lost.
>> >
>> >2. For Master database after starting sql server using
>> trace flag "-T3608"
>> >and use sp_detach_db and then copy to new drive and use
>> > sp_attach_db to attach Master database. For Tempdb
>> use ALTER DATBASE ..
>> >MODIFY FILE option. Both methodologies are detailed
>> > in the above link
>> >
>> >3. This represent the smallest amount of disk space
>> allocated to hold a
>> >file.
>> > I feel this might not reduce your I/O.
>> >
>> >
>> >4. No, Sp3a is the latest service pack.
>> >
>> >Thanks
>> >Hari
>> >MCDBA
>> >
>> >
>> >
>> >"Chip" <Chipsin007@.yahoo.com> wrote in message
>> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
>> >> Hi Group,
>> >>
>> >> For some reasons I have to pull the SQL Server
>> Production
>> >> server out of network and reinstall from OS level. I
>> have
>> >> few queries about Backing up the SQL server Databases
>> and
>> >> choosing cluster size.
>> >>
>> >> 1. Do I need to Backup/detach the Master,MSDB
databases
>> >> along with User database to restore again when SQL
>> server
>> >> is installed again freshly?. MSDB just has two
>> maintenance
>> >> plans running.I fell that I can just take the
backups of
>> >> User databases as I have to restore them on fresh
>> >> installation.
>> >>
>> >> 2. I am creating three arrays on this server
>> >> C: RAID1 Array ( OS) - Array1
>> >> D: RAID1 (SQL Tran logs files)- Array2
>> >> D: RAID5E ( SQL Data files) - Array3
>> >>
>> >> While installing SQLServer I will choose Array3 for
SQL
>> >> system databases. How do i move the master.ldf
msdb.ldf
>> >> model.ldf temp.ldf to Array2 ? does detach/attach
work
>> for
>> >> system databses?
>> >>
>> >> 3. I am choosing 8KB Cluster on NTFS instead of
Default
>> >> 4KB cluster, does this help in enhancing the access
of
>> 8K
>> >> SQL database pages in terms of I/O?
>> >>
>> >> 4. Are there any patches/fixes released after
>> >> SQLServer2000 Service Pack 3a?
>> >>
>> >> OS Windows 2000 Server SP4
>> >> SQL Server 2000 Standard Edition
>> >> IBM x250 dual PIII Xeon 700MHz
>> >> 4GB RAM
>> >> 18GB for OS on server
>> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
>> >>
>> >> Thanks for your patience
>> >>
>> >> Regards
>> >>
>> >> Chip
>> >
>> >
>> >.
>> >
>
>.
>|||That should be in the articles. You can restore MSDB as well as master. For master, you need to be in single
user mode in order to do a restore.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a001280a@.phx.gbl...
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> >--Original Message--
> >Moving databases and database files:
> >
> >
> >Moving SQL Server Databases
> >http://www.support.microsoft.com/?id=224071
> >
> >Moving Databases between Servers
> >http://www.support.microsoft.com/?id=314546
> >
> >Using WITH MOVE in a Restore to a New Location with
> Detach/Attach
> >http://support.microsoft.com/?id=221465
> >
> >How To Transfer Logins and Passwords Between SQL Servers
> >http://www.support.microsoft.com/?id=246133
> >
> >Mapping Logins & SIDs after a Restore
> >http://www.support.microsoft.com/?id=298897
> >
> >Utility to map users to the correct login
> >http://www.dbmaint.com/SyncSqlLogins.asp
> >
> >How to Resolve Permission Issues When a Database Is Moved
> Between SQL Servers
> >http://www.support.microsoft.com/?id=240872
> >
> >User Logon and/or Permission Errors After Restoring Dump
> >http://www.support.microsoft.com/?id=168001
> >
> >Disaster Recovery Articles for SQL Server
> >http://www.support.microsoft.com/?id=307775
> >
> >
> >--
> >Tibor Karaszi, SQL Server MVP
> >http://www.karaszi.com/sqlserver/default.asp
> >
> >
> >"Chip" <anonymous@.discussions.microsoft.com> wrote in
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> >> Hi Hari,
> >>
> >> Thanks for the help! one more doubt.. When I install SQL
> >> Server by default it will create Master,MSDB . How do i
> >> get rid of them and attach the last backed up master
> >> (.mdf,.ldf), MSDB(.mdf,.ldf).
> >>
> >> I guess I have to login in singleuser mode, detach them,
> >> overwrite with the backed up files then attach?
> >>
> >> Please give me step by step ( you are always awesome in
> >> dealing step by step)
> >>
> >> Sincerely
> >>
> >> Chip
> >> >--Original Message--
> >> >Hi,
> >> >
> >> >1. This link details you the steps to move the system
> >> and user databases.
> >> > http://www.support.microsoft.com/?id=224071
> >> Moving SQL Server
> >> >Databases to a New Location with Detach/Attach
> >> > It is always good to move the Master and MSDB
> >> databases to new server.
> >> >But it is a must that you should move master database
> >> > since it stores Server config, Logins
> >> permissions..If you are
> >> >notloading master all the database users chanin will be
> >> lost.
> >> >
> >> >2. For Master database after starting sql server using
> >> trace flag "-T3608"
> >> >and use sp_detach_db and then copy to new drive and use
> >> > sp_attach_db to attach Master database. For Tempdb
> >> use ALTER DATBASE ..
> >> >MODIFY FILE option. Both methodologies are detailed
> >> > in the above link
> >> >
> >> >3. This represent the smallest amount of disk space
> >> allocated to hold a
> >> >file.
> >> > I feel this might not reduce your I/O.
> >> >
> >> >
> >> >4. No, Sp3a is the latest service pack.
> >> >
> >> >Thanks
> >> >Hari
> >> >MCDBA
> >> >
> >> >
> >> >
> >> >"Chip" <Chipsin007@.yahoo.com> wrote in message
> >> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> >> >> Hi Group,
> >> >>
> >> >> For some reasons I have to pull the SQL Server
> >> Production
> >> >> server out of network and reinstall from OS level. I
> >> have
> >> >> few queries about Backing up the SQL server Databases
> >> and
> >> >> choosing cluster size.
> >> >>
> >> >> 1. Do I need to Backup/detach the Master,MSDB
> databases
> >> >> along with User database to restore again when SQL
> >> server
> >> >> is installed again freshly?. MSDB just has two
> >> maintenance
> >> >> plans running.I fell that I can just take the
> backups of
> >> >> User databases as I have to restore them on fresh
> >> >> installation.
> >> >>
> >> >> 2. I am creating three arrays on this server
> >> >> C: RAID1 Array ( OS) - Array1
> >> >> D: RAID1 (SQL Tran logs files)- Array2
> >> >> D: RAID5E ( SQL Data files) - Array3
> >> >>
> >> >> While installing SQLServer I will choose Array3 for
> SQL
> >> >> system databases. How do i move the master.ldf
> msdb.ldf
> >> >> model.ldf temp.ldf to Array2 ? does detach/attach
> work
> >> for
> >> >> system databses?
> >> >>
> >> >> 3. I am choosing 8KB Cluster on NTFS instead of
> Default
> >> >> 4KB cluster, does this help in enhancing the access
> of
> >> 8K
> >> >> SQL database pages in terms of I/O?
> >> >>
> >> >> 4. Are there any patches/fixes released after
> >> >> SQLServer2000 Service Pack 3a?
> >> >>
> >> >> OS Windows 2000 Server SP4
> >> >> SQL Server 2000 Standard Edition
> >> >> IBM x250 dual PIII Xeon 700MHz
> >> >> 4GB RAM
> >> >> 18GB for OS on server
> >> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> >> >>
> >> >> Thanks for your patience
> >> >>
> >> >> Regards
> >> >>
> >> >> Chip
> >> >
> >> >
> >> >.
> >> >
> >
> >
> >.
> >sql

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
ChipHi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
Production[vbcol=seagreen]
have[vbcol=seagreen]
and[vbcol=seagreen]
server[vbcol=seagreen]
maintenance[vbcol=seagreen]
for[vbcol=seagreen]
8K[vbcol=seagreen]
>
>.
>|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Server
s
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a00
1280a@.phx.gbl...[vbcol=seagreen]
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> and user databases.
> Moving SQL Server
> databases to new server.
> permissions..If you are
> lost.
> trace flag "-T3608"
> use ALTER DATBASE ..
> allocated to hold a
> Production
> have
> and
> server
> maintenance
> for
> 8K|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
databases[vbcol=seagreen]
backups of[vbcol=seagreen]
SQL[vbcol=seagreen]
msdb.ldf[vbcol=seagreen]
work[vbcol=seagreen]
Default[vbcol=seagreen]
of[vbcol=seagreen]
>
>.
>|||That should be in the articles. You can restore MSDB as well as master. For
master, you need to be in single
user mode in order to do a restore.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a00
1280a@.phx.gbl...[vbcol=seagreen]
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> Detach/Attach
> Between SQL Servers
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> databases
> backups of
> SQL
> msdb.ldf
> work
> Default
> of

Friday, March 9, 2012

pl/sql wrappers newbie guide?

Does anyone know of a good web reasource for writing wrappers for a low level c program?
I've been given the task to write a simple wrapper by tomorrow so I don't have time to get to the book store for an O'Reilly book.
Many thanks!
CraigTry: asktom.oracle.com

Search for "external procedure" "language c"|||Thanks Tony!

Wednesday, March 7, 2012

PIVOT/CROSS TAB/Converting Rows to (multiple group) Columns

Hello All,

I am trying to convert the rows in a table to columns. I have found similar threads on the forum addressing this issue on a high level suggesting the use of cursors, PIVOT Transform, and other means. However, I would appreciate if someone can provide a concrete example in T-Sql for the following subset of my problem.

Consider that we have Product Category, Product and its monthly sales information retrieved as follows:

CategoryID ProductID ProductName Month UnitPrice QtySold SalesAmount 1 1 Panel Jan 5 10 50 1 1 Panel Feb 5 15 75 1 1 Panel Mar 5 20 100 1 2 Frame Jan 10 30 300 1 2 Frame Feb 10 25 250 1 2 Frame Mar 10 20 200 1 3 Glass Jan 20 10 200 1 3 Glass Feb 20 20 400 1 3 Glass Mar 20 30 600

I would like it to be converted into following result set:

CategoryID ProductID ProductName UnitPrice QtySold_Jan SalesAmt_Jan QtySold_Feb SalesAmt_Feb QtySold_Mar SalesAmt_Mar 1 1 Panel 5 10 50 15 75 20 100 1 2 Frame 10 30 300 25 250 20 200 1 3 Glass 20 10 200 20 400 30 600

I have purposefully included QtySold here as I need to display both Quantity and Sales as measured column groups in my report. Can this be achieved in sql? I would appreciate any responses.

Thanks.

What you are attempting to do is BEST done with the client application. SQL Server excels at storing and retreiving data. These kinds of 'transformations', while possible, are not the best use of a very expensive resource.

However, if you must, these articles demonstrate several variations of how to accomplish your goal -and they offer 'concrete' examples

Pivot Tables -A simple way to perform crosstab operations
http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1131829,00.html

Pivot Tables - How to rotate a table in SQL Server
http://support.microsoft.com/default.aspx?scid=kb;en-us;175574

Pivot Tables -Dynamic Cross-Tabs
http://www.sqlteam.com/item.asp?ItemID=2955

Pivot Tables - Crosstab Pivot-table Workbench
http://www.simple-talk.com/sql/t-sql-programming/crosstab-pivot-table-workbench/

.

Monday, February 20, 2012

Pivot Error

Hi :

I am getting the following error message when I am trying to do the Pivot operation.

Msg 265, Level 16, State 1, Line 1

The column name "FirstName" specified in the PIVOT operator conflicts with the existing column name in the PIVOT argument.

Msg 265, Level 16, State 1, Line 1

The column name "LastName" specified in the PIVOT operator conflicts with the existing column name in the PIVOT argument.

Msg 8156, Level 16, State 1, Line 1

The column 'FirstName' was specified multiple times for 'Pvt'.

My SQL Query is:

SELECT UserID,FirstName,LastName

FROM

(

SELECT UserID,FirstName,LastName

FROM Tempreport AS ATR

PIVOT (

MAX(QuestionAnswer)

FOR QuestionText

IN ([CompanyAddress1],[CompanyAddress2],[CompanyName],[Country],[EmailAddress],[FirstName],[LastName],[PhoneNumber],[PostalCode],[Select the Category that best describes your Industry],[Select the Category that best describes your role],[Select the Category that best describes your title],[Town])) as Pvt

) Result (UserID,FirstName,LastName)

Here is the DDL:

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'LastName','Testing2')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Town','Testing6')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Country','Testing7')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other')

CREATE TABLE Tempreport

(UserID INT,

LastName VARCHAR(255),

FirstName VARCHAR(255),

OrderNumber INT,

QuestionText VARCHAR(255),

QuestionAnswer VARCHAR(255)

)

Drop table tempreport.

Can anyone please let me know what I am doing wrong and how to fix this error?. looks like I cant select the same column inside the pivot and outside the pivot. In such a case what is my alternative?.

Any help is appreciated.

Thanks

M

? What output are you looking for? -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Meher@.discussions.microsoft.com> wrote in message news:70fe23b8-d832-4a8d-b10e-e4bfec6c69bb@.discussions.microsoft.com... Hi : I am getting the following error message when I am trying to do the Pivot operation. Msg 265, Level 16, State 1, Line 1 The column name "FirstName" specified in the PIVOT operator conflicts with the existing column name in the PIVOT argument. Msg 265, Level 16, State 1, Line 1 The column name "LastName" specified in the PIVOT operator conflicts with the existing column name in the PIVOT argument. Msg 8156, Level 16, State 1, Line 1 The column 'FirstName' was specified multiple times for 'Pvt'. My SQL Query is: SELECT UserID,FirstName,LastName FROM ( SELECT UserID,FirstName,LastName FROM Tempreport AS ATR PIVOT ( MAX(QuestionAnswer) FOR QuestionText IN ([CompanyAddress1],[CompanyAddress2],[CompanyName],[Country],[EmailAddress],[FirstName],[LastName],[PhoneNumber],[PostalCode],[Select the Category that best describes your Industry],[Select the Category that best describes your role],[Select the Category that best describes your title],[Town])) as Pvt ) Result (UserID,FirstName,LastName) Here is the DDL: INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'LastName','Testing2') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Town','Testing6') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Country','Testing7') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other') CREATE TABLE Tempreport (UserID INT, LastName VARCHAR(255), FirstName VARCHAR(255), OrderNumber INT, QuestionText VARCHAR(255), QuestionAnswer VARCHAR(255) ) Drop table tempreport. Can anyone please let me know what I am doing wrong and how to fix this error?. looks like I cant select the same column inside the pivot and outside the pivot. In such a case what is my alternative?. Any help is appreciated. Thanks M|||

The output I am looking is for the Number of Questions that the survey has the responses something like this:

LastName FirstName UserID Address1 Address2 Select the category Select the role

Veerman Maek 10 123 XXX Other Other

Mark Smith 20 324 YYY IT Developer

|||? Something like this, perhaps: CREATE TABLE Tempreport (UserID INT,LastName VARCHAR(255),FirstName VARCHAR(255),OrderNumber INT,QuestionText VARCHAR(255),QuestionAnswer VARCHAR(255)) INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'LastName','Testing2')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'Town','Testing6')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'Country','Testing7')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other')INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other')go SELECT UserID, FName, LName, TotalAnswers, pvt.*FROM ( SELECT UserID, FirstName AS FName, LastName AS LName, QuestionText, QuestionAnswer, COUNT(*) OVER(PARTITION BY UserId) AS TotalAnswers FROM Tempreport) AS ATRPIVOT ( MAX(QuestionAnswer) FOR QuestionText IN ([CompanyAddress1],[CompanyAddress2],[CompanyName], [Country],[EmailAddress],[FirstName],[LastName], [PhoneNumber],[PostalCode], [Select the Category that best describes your Industry], [Select the Category that best describes your role], [Select the Category that best describes your title],[Town])) as Pvtgo drop table tempreportgo -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Meher@.discussions.microsoft.com> wrote in message news:4bc96011-34ee-46fb-bdfd-822456ee11e4@.discussions.microsoft.com... The output I am looking is for the Number of Questions that the survey has the responses something like this: LastName FirstName UserID Address1 Address2 Select the category Select the role Veerman Maek 10 123 XXX Other Other Mark Smith 20 324 YYY IT Developer|||Thanks Adam. It works!!!.|||

ok there seems to be another issue. For some questions in the survey, the respoonse is more than one. Because there is a check box on the web and the user can choose more than one response. in that case when I pivot the question text it shows up as null since the question text is inserted only once. How do we show all the possible answers (in other words concatenate the answers).

I tried to follow the article of http://www.aspfaq.com/show.asp?id=2529 and use the cross apply operator in SQL Server 2005 but it still shows as null. My query for cross apply was along the lines of

Select UserID,

QuestionText,

QuestionAnswer=LEFT(o.list,LEN(o.list) -1)

FROM Tempreport T

CROSS APPLY

(SELECT

CONVERT(VARCHAR(500),QuestionAnswer)+',' AS [text()]

FROM TempReport T2

WHERE T.UserID=T2.UserID

ORDER BY QuestionAnswer

FOR XML PATH('')

) o (list)

ORDER BY QuestionText

How do I incorporate the Cross apply into my original solution to come out with the question and show all the possible answers concatenated?. I dont want to see NULLs. Any re-write is really helpful.

Thanks

DDL is given below:


CREATE TABLE Tempreport

(UserID INT,

LastName VARCHAR(255),

FirstName VARCHAR(255),

OrderNumber INT,

QuestionText VARCHAR(255),

QuestionAnswer VARCHAR(255)

)

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'LastName','Testing2')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Town','Testing6')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Country','Testing7')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'Please indicate which apps you are interested in','Accounting')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,NULL,'Payroll')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,NULL'Unavailable to attend')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,'How often do you pay','Weekly')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,Null,'Fortnightly')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,Null,'Four weekly')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,Null,'Monthly')
INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)
VALUES (200253,'Veerman','Mark',2,Null,'other')

--Original solution

DECLARE @.ListLen INT

DECLARE @.INDEX INT

DECLARE @.month nvarchar(25)

DECLARE @.year nvarchar(25)

DECLARE @.strResult VARCHAR(500)

select @.cstlist = (select DISTINCT QUOTENAME(LTRIM(RTRIM(QuestionText)))+','as [text()]

from Tempreport

order by QUOTENAME(LTRIM(RTRIM(QuestionText)))+','

for xml path(''))

SET @.ListLen=LEN(@.cstList)

SET @.cstList=LEFT(@.cstList,(@.ListLen-1))

SET @.strSQL=@.cstList

PRINT (@.strSQL)

select @.sql = 'SELECT UserID,FName,LName,pvt.* FROM

(SELECT UserID,FirstName AS FName,

LastName AS LName,QuestionText,QuestionAnswer,

COUNT(*) OVER(PARTITION BY UserId) AS TotalAnswers

FROM Tempreport) AS ATR '

+ 'PIVOT (MAX(QuestionAnswer) FOR QuestionText IN (' + @.strSQL+ ')) AS Pvt'

PRINT (@.sql)

--EXEC (@.sql)

|||? How do you know which answers belong to which questions? Can you introduce a QuestionId column or something along those lines? Otherwise, I don't think there's any way to solve this problem... -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Meher@.discussions.microsoft.com> wrote in message news:16b34575-d985-4cde-9a9a-844627b4f068@.discussions.microsoft.com... ok there seems to be another issue. For some questions in the survey, the respoonse is more than one. Because there is a check box on the web and the user can choose more than one response. in that case when I pivot the question text it shows up as null since the question text is inserted only once. How do we show all the possible answers (in other words concatenate the answers). I tried to follow the article of http://www.aspfaq.com/show.asp?id=2529 and use the cross apply operator in SQL Server 2005 but it still shows as null. My query for cross apply was along the lines of|||

Hi Adam:

I have added the questionID (column name QuestionTextID) as you have suggested. I am helping some one with this problem and their db design is not good. The new DDL is given below:

CREATE TABLE Tempreport

(UserID INT,

LastName VARCHAR(255),

FirstName VARCHAR(255),

OrderNumber INT,

QuestionTextID INT IDENTITY (1,1),

QuestionText VARCHAR(255),

QuestionAnswer VARCHAR(255)

)

GO

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'LastName','Testing2')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Town','Testing6')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Country','Testing7')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Please indicate which apps you are interested in','Accounting')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,NULL,'Payroll')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,NULL,'Unavailable to attend')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'How often do you pay','Weekly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,Null,'Fortnightly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,Null,'Four weekly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,Null,'Monthly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,Null,'other')

|||? Unfortunately, that won't work quite right as-is. It needs to be QuestionId, and needs to correspond to each question. So every answer to the same question will have the same QuestionId. That way, you can simply correlate in the FOR XML PATH subquery: SELECT UserID, FName, LName, TotalAnswers, pvt.*FROM ( SELECT UserID, FirstName AS FName, LastName AS LName, QuestionText, ( SELECT QuestionAnswer + ',' AS [data()] FROM TempReport TR2 WHERE TR2.UserId = TempReport.UserId AND TR2.QuestionId = TempReport.QuestionId FOR XML PATH('') ) AS QuestionAnswers, COUNT(*) OVER(PARTITION BY UserId) AS TotalAnswers FROM Tempreport WHERE QuestionText IS NOT NULL) AS ATRPIVOT ( MAX(QuestionAnswer) FOR QuestionText IN ([CompanyAddress1],[CompanyAddress2],[CompanyName], [Country],[EmailAddress],[FirstName],[LastName], [PhoneNumber],[PostalCode], [Select the Category that best describes your Industry], [Select the Category that best describes your role], [Select the Category that best describes your title],[Town])) as Pvtgo -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Meher@.discussions.microsoft.com> wrote in message news:0191df4c-9ecb-4505-8509-e8b5836f73a8@.discussions.microsoft.com... Hi Adam: I have added the questionID (column name QuestionTextID) as you have suggested. I am helping some one with this problem and their db design is not good. The new DDL is given below: CREATE TABLE Tempreport (UserID INT, LastName VARCHAR(255), FirstName VARCHAR(255), OrderNumber INT, QuestionTextID INT IDENTITY (1,1), QuestionText VARCHAR(255), QuestionAnswer VARCHAR(255) ) GO INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'LastName','Testing2') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Town','Testing6') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Country','Testing7') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'Please indicate which apps you are interested in','Accounting') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,NULL,'Payroll') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,NULL,'Unavailable to attend') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,'How often do you pay','Weekly') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,Null,'Fortnightly') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,Null,'Four weekly') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,Null,'Monthly') INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer) VALUES (200253,'Veerman','Mark',2,Null,'other')|||Any ideas?.|||

Thanks Adam, I can make it as the same questionID for the answer as you have suggested.
In that case, would your solution hold good or does it need any more changes?.
Here is the DDL:

CREATE TABLE Tempreport

(UserID INT,

LastName VARCHAR(255),

FirstName VARCHAR(255),

OrderNumber INT,

QuestionTextID INT IDENTITY (1,1),

QuestionText VARCHAR(255),

QuestionAnswer VARCHAR(255)

)

GO

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'FirstName','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'LastName','Testing2')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyName','Testing3')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress1','Testing4')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'CompanyAddress2','Testing5')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Town','Testing6')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Country','Testing7')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PostalCode','Testing8')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'PhoneNumber','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'EmailAddress','Testing9')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your Industry','Testing1')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your role','Other')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',2,'Select the Category that best describes your title','Other')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',12,'Please indicate which apps you are interested in','Accounting')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',12,NULL,'Payroll')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',12,NULL,'Unavailable to attend')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',32,'How often do you pay','Weekly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',32,Null,'Fortnightly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',32,Null,'Four weekly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',32,Null,'Monthly')

INSERT INTO Tempreport (UserID,LastName,FirstName,OrderNumber,QuestionText,QuestionAnswer)

VALUES (200253,'Veerman','Mark',32,Null,'other')

|||

Hi Adam:

Dont worry about this. I got it working after I changed the questionID to be the same for the check box list. Here is the final query that brings back the data i want.

Thanks a lot for your tremendous help. you are awesome!!!

SELECT

UserID,

FName,

LName,

TotalAnswers,

pvt.*

FROM

(

SELECT

UserID,

FirstName AS FName,

LastName AS LName,

QuestionText,

(

SELECT QuestionAnswer + ',' AS [data()]

FROM TempReport TR2

WHERE

TR2.UserId = TempReport.UserId

AND TR2.QuestionTextId = TempReport.QuestionTextId

FOR XML PATH('')

) AS QuestionAnswers,

COUNT(*) OVER(PARTITION BY UserId) AS TotalAnswers

FROM Tempreport

WHERE QuestionText IS NOT NULL

) AS ATR

PIVOT

(

MAX(QuestionAnswers)

FOR QuestionText

IN ([CompanyAddress1],[CompanyAddress2],[CompanyName],

[Country],[EmailAddress],[FirstName],[LastName],

[PhoneNumber],[PostalCode],

[Select the Category that best describes your Industry],

[Select the Category that best describes your role],

[Please indicate which apps you are interested in],[Town],

[How often do you pay])

) as Pvt

go