Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Friday, March 30, 2012

Problems with TLog Backup

To All:
TLog backups have been going smoothly for many months. Now, the following
messages are generated (always together) with increasing frequency.
3041 :
BACKUP failed to complete the command backup log "Apollo" to
VIRTUAL_DEVICE='VNBU0-2416-2316' with blocksize = 512, maxtransfersize = 65536, buffercount = 1
18210 :
BackupVirtualDeviceSet::Initialize: CoCreateInstance failure on
backup device 'VNBU0-2416-2316'. Operating system error -2147467262(No such
interface supported).
The fellow in charge of backups wants me to reboot the server daily. This
isn't the answer to this problem. Any suggestions are appreciated.
Regards,
Michael CliffordIs the backup device local ?
If not can you backup locally ?
--
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Michael Clifford" <mjclifford_nospam@.mindspring.com> wrote in message
news:ufZJblQiDHA.2164@.TK2MSFTNGP09.phx.gbl...
> To All:
> TLog backups have been going smoothly for many months. Now, the following
> messages are generated (always together) with increasing frequency.
> 3041 :
> BACKUP failed to complete the command backup log "Apollo" to
> VIRTUAL_DEVICE='VNBU0-2416-2316' with blocksize = 512, maxtransfersize => 65536, buffercount = 1
> 18210 :
> BackupVirtualDeviceSet::Initialize: CoCreateInstance failure on
> backup device 'VNBU0-2416-2316'. Operating system error -2147467262(No
such
> interface supported).
>
> The fellow in charge of backups wants me to reboot the server daily. This
> isn't the answer to this problem. Any suggestions are appreciated.
>
> Regards,
> Michael Clifford
>
>
>|||Allan,
Backups are done with an enterprise level Veritas SQL Agent on the local box
and a tape backup server remotely.
Michael
"Allan Mitchell" <allan@.no-spam.sqldts.com> wrote in message
news:uEA1oASiDHA.1508@.TK2MSFTNGP10.phx.gbl...
> Is the backup device local ?
> If not can you backup locally ?
> --
> --
> Allan Mitchell (Microsoft SQL Server MVP)
> MCSE,MCDBA
> www.SQLDTS.com
> I support PASS - the definitive, global community
> for SQL Server professionals - http://www.sqlpass.org
> "Michael Clifford" <mjclifford_nospam@.mindspring.com> wrote in message
> news:ufZJblQiDHA.2164@.TK2MSFTNGP09.phx.gbl...
> > To All:
> >
> > TLog backups have been going smoothly for many months. Now, the
following
> > messages are generated (always together) with increasing frequency.
> >
> > 3041 :
> >
> > BACKUP failed to complete the command backup log "Apollo" to
> > VIRTUAL_DEVICE='VNBU0-2416-2316' with blocksize = 512, maxtransfersize => > 65536, buffercount = 1
> >
> > 18210 :
> >
> > BackupVirtualDeviceSet::Initialize: CoCreateInstance failure on
> > backup device 'VNBU0-2416-2316'. Operating system error -2147467262(No
> such
> > interface supported).
> >
> >
> >
> > The fellow in charge of backups wants me to reboot the server daily.
This
> > isn't the answer to this problem. Any suggestions are appreciated.
> >
> >
> >
> > Regards,
> >
> > Michael Clifford
> >
> >
> >
> >
> >
> >
>|||OK so these are those "Suck the guts" backups from an "Agent" ?
Can you issue a simple BACKUP DATABASE <<name>> TO DISK = '<<local disk
file>>'
Have you seen this
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q323/6/02.asp&NoWebContent=1
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Michael Clifford" <mjclifford_nospam@.mindspring.com> wrote in message
news:uzrz%23bZiDHA.1624@.tk2msftngp13.phx.gbl...
> Allan,
> Backups are done with an enterprise level Veritas SQL Agent on the local
box
> and a tape backup server remotely.
> Michael
>
> "Allan Mitchell" <allan@.no-spam.sqldts.com> wrote in message
> news:uEA1oASiDHA.1508@.TK2MSFTNGP10.phx.gbl...
> > Is the backup device local ?
> > If not can you backup locally ?
> >
> > --
> > --
> >
> > Allan Mitchell (Microsoft SQL Server MVP)
> > MCSE,MCDBA
> > www.SQLDTS.com
> > I support PASS - the definitive, global community
> > for SQL Server professionals - http://www.sqlpass.org
> >
> > "Michael Clifford" <mjclifford_nospam@.mindspring.com> wrote in message
> > news:ufZJblQiDHA.2164@.TK2MSFTNGP09.phx.gbl...
> > > To All:
> > >
> > > TLog backups have been going smoothly for many months. Now, the
> following
> > > messages are generated (always together) with increasing frequency.
> > >
> > > 3041 :
> > >
> > > BACKUP failed to complete the command backup log "Apollo" to
> > > VIRTUAL_DEVICE='VNBU0-2416-2316' with blocksize = 512, maxtransfersize
=> > > 65536, buffercount = 1
> > >
> > > 18210 :
> > >
> > > BackupVirtualDeviceSet::Initialize: CoCreateInstance failure
on
> > > backup device 'VNBU0-2416-2316'. Operating system error -2147467262(No
> > such
> > > interface supported).
> > >
> > >
> > >
> > > The fellow in charge of backups wants me to reboot the server daily.
> This
> > > isn't the answer to this problem. Any suggestions are appreciated.
> > >
> > >
> > >
> > > Regards,
> > >
> > > Michael Clifford
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>sql

Problems with Switching partitions

Hi,

Im trying to switch a partition from partitioned table to a non partitioned table. I am getting the following error.

eCertified.dbo.Carrier_Trip_AvailabilitySwitch.PK_Carrier_Trip_AvailabilitySwitch_1' is in filegroup 'PRIMARY' and partition 24 of index 'eCertified.dbo.Carrier_Trip_Availability_Partition.PK_Carrier_Trip_Availability_Partition' is in filegroup 'SECONDARY24'. [SQLSTATE 42000] (Error 4939). The step failed.

The table one has 24 partitions and it has a partitioned clustered index. PK_Carrier_Trip_AvailabilitySwitch is the primary key in the non partitioned table and its is in the primary file group while the PK_Carrier_Trip_Availability_Partition is the primary key iin the partitioned table and its in the file group secondary 24.

Please let me know how to solve this issue.

When you switch a partition of a partitioned table to a non-partitioned table or a partition of another partitioned table, the source partition and the target table/partition must be in the same file group.

Wednesday, March 28, 2012

Problems with sql-statement / making rows to columns...

I have the following problem:

I'd like to display these rows as columns via an sql-statement:

Input

Code Snippet

4 10000000 Juice
4 10000000 Coca-Cola
4 10000000 Orange
4 10000000 Walmart

Output

Code Snippet

4 10000000 Juice Coca-Cola Orange Walmart

To get the data within the input table, I momentarily use this select:

Code Snippet

SELECT artikel.lfdnr,

artikel.artnr1,

arteinordnung.einordnung

FROM artikel

LEFTJOIN aeinord ON artikel.lfdnr = aeinord.artnr

LEFTJOIN arteinordnung ON aeinord.kriterium = arteinordnung.kriterium

AND aeinord.einordnung = arteinordnung.lfdnr

ORDERBY artikel.lfdnr

Any suggestions on how to modify this statement to get the data into the output-format?

Any help's appreciated!

here you go..

Code Snippet

Create Table #data (

[Col1] int ,

[Col2] int ,

[Col3] varchar(20)

);

Insert Into #data Values('4','10000000','Juice');

Insert Into #data Values('4','10000000','Coca-Cola');

Insert Into #data Values('4','10000000','Orange');

Insert Into #data Values('4','10000000','Walmart');

Insert Into #data Values('5','10000000','Juice');

Insert Into #data Values('5','10000000','Coca-Cola');

Insert Into #data Values('5','10000000','Orange');

--For SQL Server 2005

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

) as Pvt

/*

--If your intention is concatinate all the row data in one column

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

, Result

as

(

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5])--,...[n])

) as Pvt

)

Select

Col1

, Col2

, Isnull([1] +';','') + Isnull([2] +';','') + Isnull([3] +';','') + Isnull([4] +';','') + Isnull([5] +';','') as OneColumn

From

Result

*/

--For SQL Server 2000

Select * into #Temp From #Data

Alter table #Temp Add RowId Int Identity(1,1)

Alter table #Temp Add GroupedRowId int

Update #Temp

Set GroupedRowId = RowId - (Select Min(RowId)-1 From #Temp Sub Where Sub.Col1 = #Temp.Col1 And Sub.Col2 = #Temp.Col2)

Select

Col1,

Col2,

Max(Case When GroupedRowId=1 Then Col3 End),

Max(Case When GroupedRowId=2 Then Col3 End),

Max(Case When GroupedRowId=3 Then Col3 End),

Max(Case When GroupedRowId=4 Then Col3 End),

Max(Case When GroupedRowId=5 Then Col3 End)

-- ... ,Max(Case When GroupedRowId=n Then Col3 End)

From

#Temp

Group By

Col1,Col2

/*

--If your intention is concatinate all the row data in one column

Select

Col1,

Col2,

Isnull([1] +';','') + Isnull([2] +';','') + Isnull([3] +';','') + Isnull([4] +';','') + Isnull([5] +';','') as OneColumn

From

(

Select

Col1,

Col2,

Max(Case When GroupedRowId=1 Then Col3 End) [1],

Max(Case When GroupedRowId=2 Then Col3 End) [2],

Max(Case When GroupedRowId=3 Then Col3 End) [3],

Max(Case When GroupedRowId=4 Then Col3 End) [4],

Max(Case When GroupedRowId=5 Then Col3 End) [5]

-- ... ,Max(Case When GroupedRowId=n Then Col3 End)

From

#Temp

Group By

Col1,Col2

) as Result

*/

Drop Table #Temp

|||

Manivannan.D.Sekaran wrote:

here you go..

Thanks, that was a huge post

I fully understand your solution, but I have the problem that Juice, Coca-Cola,Orange and Walmart aren't the only possible values. There can be 1...n values within those row...

So, I need a solution that can extract dynamically those values without doing this manually:

Insert Into #data Values('4','10000000','Juice');

Insert Into #data Values('4','10000000','Coca-Cola');

Insert Into #data Values('4','10000000','Orange');

Insert Into #data Values('4','10000000','Walmart');

Insert Into #data Values('5','10000000','Juice');

Insert Into #data Values('5','10000000','Coca-Cola');

Insert Into #data Values('5','10000000','Orange');


Any suggestions?!
|||

It appears that Mani created a sample table, and loaded it with sample data so he could try to work out a solution for you. (Since you didn't bother to offer DDL or sample data.)

It would appear that perhaps you didn't really 'fully understand' Manivannan's suggested solution -since you didn't follow the creation and poputation of the sample data...

I think that the solution that follows the loading of the sample data could most likely be altered to fit your table structure -whatever that may be...

(It does look like he went the 'extra step'...)

|||

your select statement is write

for output:

you can format it inside the program

like that

duppose you put the artikel.lfdnr in x1 and artikel.artnr1 in x2 and arteinordnung.einordnung in x3

s= "4 10000000 "

if (x1=4 and x2= 10000000)

S=S+x3

|||

Ok, so instead of the creation process via "CREATE table #data" I'd let run my standard SQL SELECT. Then I've got all the possible values within the output table. Then I encounter this problem:

Code Snippet

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

) as Pvt

It looks like I need to know all the possible values for this part, or am I wrong:

Code Snippet

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

|||

Code Snippet

createfunction dbo.MultiList ( @.col1 asint, @.col2 asint)

returnsvarchar(8000)

as

begin

declare @.list varchar(8000)

select @.list =coalesce( @.list +', ','')+ Col3

from data where Col1 = @.col1 and Col2 = @.col2

return @.list

end

GO

CreateTable data (

[Col1] int,

[Col2] int,

[Col3] varchar(20)

);

InsertInto data Values('4','10000000','Juice');

InsertInto data Values('4','10000000','Coca-Cola');

InsertInto data Values('4','10000000','Orange');

InsertInto data Values('4','10000000','Walmart');

InsertInto data Values('5','10000000','Juice');

InsertInto data Values('5','10000000','Coca-Cola');

InsertInto data Values('5','10000000','Orange');

select col1, col2, dbo.MultiList(col1, col2)as items

from data

groupby col1, col2

|||

Mh, maybe you're right. I am really struggling in setting up the correct SQL-statement...

At the moment I don't see the possibility to adapt the pivot-function to my SQL-statement.

|||

Rather than the CTE, you may be better served by examining the 'MultiList' function that DaleJ offered.

|||

The multilist function is completely new to me. How do I approach it at best?

To understand the functionality better I'd like to execute my standard SELECT, then I got all the relevant data within a table. Is it possible to skip this procedure in your multilist function, or do I need to set it up like that?

Code Snippet

CreateTable data (

[Col1] int,

[Col2] int,

[Col3] varchar(20)

);

Somehow I feel not comfortable with the "INSERT INTO ... VALUES (..., ..., ...)" command. It implies that I have to add once all possible list-entries, am I wrong?

|||

Somehow I feel not comfortable with the "INSERT INTO ... VALUES (..., ..., ...)" command. It implies that I have to add once all possible list-entries, am I wrong?

Yes, you are wrong about that. In the previous posting, a sample table was created and it was populated with sample data. You DO NOT USE THE SAMPLE DATA -you use your own table and column names, following the example.

Create the MultiList function in your database, and then execute your 'standard SELECT' -carefully following the example.

|||

I think the way I'd like to format the data is a bit off... I just took a look at the raw data, and it appears to me that the problem isn't as complicated as I thought.

Table1 has a Parent-Child-hierarchy structure... Table2 connects Table1 and the Article_Table via the 'ArtNr'.

Code Snippet

Table1:

LfdNr Kriterium Einordnung

0 1 Marke

0 2 Markenhauptgruppe

0 3 Markenuntergruppe

1 1 Eigenmarke

2 1 Fremdmarke

2 2 Frische

2 3 Valensina

3 2 Handelsmarke

3 3 Chiquita

4 2 Paradise

4 3 Rio Doro

5 2 Lizenzmarke

5 3 Hitchcock

...

Code Snippet

Table2:

ArtNr LfdNr Kriterium

4711 2 1

4711 3 2

4711 4 3

5000 1 1

5000 2 2

...

The Output table should look like this:

Code Snippet

Desired Output:

ArtNr Marke Markenhauptgruppe Markenuntergruppe

4711 Fremdmarke Handelsmarke Rio Doro

5000 Eigenmarke Frische

|||

here it is, (replace the #table1 & #tabl2 with your orginal table name on the Sql Server 2000 & 2005 query)

Code Snippet

Create Table #table1 (

[LfdNr] int ,

[Kriterium] int ,

[Einordnung] Varchar(100)

);

Insert Into #table1 Values('0','1','Marke');

Insert Into #table1 Values('0','2','Markenhauptgruppe');

Insert Into #table1 Values('0','3','Markenuntergruppe');

Insert Into #table1 Values('1','1','Eigenmarke');

Insert Into #table1 Values('2','1','Fremdmarke');

Insert Into #table1 Values('2','2','Frische');

Insert Into #table1 Values('2','3','Valensina');

Insert Into #table1 Values('3','2','Handelsmarke');

Insert Into #table1 Values('3','3','Chiquita');

Insert Into #table1 Values('4','2','Paradise');

Insert Into #table1 Values('4','3','Rio Doro');

Insert Into #table1 Values('5','2','Lizenzmarke');

Insert Into #table1 Values('5','3','Hitchcock');

Create Table #table2 (

[ArtNr] Varchar(100) ,

[LfdNr] int ,

[Kriterium] int

);

Insert Into #table2 Values('4711','2','1');

Insert Into #table2 Values('4711','3','2');

Insert Into #table2 Values('4711','4','3');

Insert Into #table2 Values('5000','1','1');

Insert Into #table2 Values('5000','2','2');

Code Snippet

--SQL Server 2000

Select

[ArtNr]

,[Einordnung]

into #Temp

from

#table2 A

Join #table1 B on

A.[LfdNr]=B.[LfdNr]

And A.[Kriterium] = B.[Kriterium]

Order By

1,2

Alter table #Temp Add RowId int identity(1,1), GroupId int

Update #Temp

Set

GroupId = RowId - (Select Min(RowId) -1 From #Temp Sub Where Sub.[ArtNr] = #Temp.[ArtNr])

select

[ArtNr]

,Isnull(Max(Case When GroupId = 1 Then [Einordnung] End),'') as [Marke]

,Isnull(Max(Case When GroupId = 2 Then [Einordnung] End),'') as [Markenhauptgruppe]

,Isnull(Max(Case When GroupId = 3 Then [Einordnung] End),'') as [Markenuntergruppe]

from

#temp

Group By

[ArtNr]

Code Snippet

--SQL Server 2005

;With CTE

as

(

Select

[ArtNr]

,[Einordnung]

,Row_Number() Over (Partition By [ArtNr] Order By [ArtNr]) GroupId

from

#table2 A

Join #table1 B on

A.[LfdNr]=B.[LfdNr]

And A.[Kriterium] = B.[Kriterium]

)

Select

[ArtNr]

,Isnull([1] ,'') as [Marke]

,Isnull([2] ,'') as [Markenhauptgruppe]

,Isnull([3] ,'') as [Markenuntergruppe]

from

CTE

Pivot

(

Max([Einordnung]) For GroupId in ([1],[2],[3])

) Pvt

|||

Awesome, this is it! Many thanks! But I've got another problem:

(SSMS marks the '(' near PVT as Error?)

Meldung 102, Ebene 15, Status 1, Zeile 21

Falsche Syntax in der N?he von '('.

in english: ;-)

Message 102, Level 15, Status 1, Row 21

False Syntax near '('.

I don't know exactly what's wrong with the statement, to me it seems fine...

|||anyone?

Problems with sql-statement / making rows to columns...

I have the following problem:

I'd like to display these rows as columns via an sql-statement:

Input

Code Snippet

4 10000000 Juice
4 10000000 Coca-Cola
4 10000000 Orange
4 10000000 Walmart

Output

Code Snippet

4 10000000 Juice Coca-Cola Orange Walmart

To get the data within the input table, I momentarily use this select:

Code Snippet

SELECT artikel.lfdnr,

artikel.artnr1,

arteinordnung.einordnung

FROM artikel

LEFT JOIN aeinord ON artikel.lfdnr = aeinord.artnr

LEFT JOIN arteinordnung ON aeinord.kriterium = arteinordnung.kriterium

AND aeinord.einordnung = arteinordnung.lfdnr

ORDER BY artikel.lfdnr

Any suggestions on how to modify this statement to get the data into the output-format?

Any help's appreciated!

here you go..

Code Snippet

Create Table #data (

[Col1] int ,

[Col2] int ,

[Col3] varchar(20)

);

Insert Into #data Values('4','10000000','Juice');

Insert Into #data Values('4','10000000','Coca-Cola');

Insert Into #data Values('4','10000000','Orange');

Insert Into #data Values('4','10000000','Walmart');

Insert Into #data Values('5','10000000','Juice');

Insert Into #data Values('5','10000000','Coca-Cola');

Insert Into #data Values('5','10000000','Orange');

--For SQL Server 2005

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

) as Pvt

/*

--If your intention is concatinate all the row data in one column

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

, Result

as

(

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5])--,...[n])

) as Pvt

)

Select

Col1

, Col2

, Isnull([1] +';','') + Isnull([2] +';','') + Isnull([3] +';','') + Isnull([4] +';','') + Isnull([5] +';','') as OneColumn

From

Result

*/

--For SQL Server 2000

Select * into #Temp From #Data

Alter table #Temp Add RowId Int Identity(1,1)

Alter table #Temp Add GroupedRowId int

Update #Temp

Set GroupedRowId = RowId - (Select Min(RowId)-1 From #Temp Sub Where Sub.Col1 = #Temp.Col1 And Sub.Col2 = #Temp.Col2)

Select

Col1,

Col2,

Max(Case When GroupedRowId=1 Then Col3 End),

Max(Case When GroupedRowId=2 Then Col3 End),

Max(Case When GroupedRowId=3 Then Col3 End),

Max(Case When GroupedRowId=4 Then Col3 End),

Max(Case When GroupedRowId=5 Then Col3 End)

-- ... ,Max(Case When GroupedRowId=n Then Col3 End)

From

#Temp

Group By

Col1,Col2

/*

--If your intention is concatinate all the row data in one column

Select

Col1,

Col2,

Isnull([1] +';','') + Isnull([2] +';','') + Isnull([3] +';','') + Isnull([4] +';','') + Isnull([5] +';','') as OneColumn

From

(

Select

Col1,

Col2,

Max(Case When GroupedRowId=1 Then Col3 End) [1],

Max(Case When GroupedRowId=2 Then Col3 End) [2],

Max(Case When GroupedRowId=3 Then Col3 End) [3],

Max(Case When GroupedRowId=4 Then Col3 End) [4],

Max(Case When GroupedRowId=5 Then Col3 End) [5]

-- ... ,Max(Case When GroupedRowId=n Then Col3 End)

From

#Temp

Group By

Col1,Col2

) as Result

*/

Drop Table #Temp

|||

Manivannan.D.Sekaran wrote:

here you go..

Thanks, that was a huge post

I fully understand your solution, but I have the problem that Juice, Coca-Cola,Orange and Walmart aren't the only possible values. There can be 1...n values within those row...

So, I need a solution that can extract dynamically those values without doing this manually:

Insert Into #data Values('4','10000000','Juice');

Insert Into #data Values('4','10000000','Coca-Cola');

Insert Into #data Values('4','10000000','Orange');

Insert Into #data Values('4','10000000','Walmart');

Insert Into #data Values('5','10000000','Juice');

Insert Into #data Values('5','10000000','Coca-Cola');

Insert Into #data Values('5','10000000','Orange');


Any suggestions?!
|||

It appears that Mani created a sample table, and loaded it with sample data so he could try to work out a solution for you. (Since you didn't bother to offer DDL or sample data.)

It would appear that perhaps you didn't really 'fully understand' Manivannan's suggested solution -since you didn't follow the creation and poputation of the sample data...

I think that the solution that follows the loading of the sample data could most likely be altered to fit your table structure -whatever that may be...

(It does look like he went the 'extra step'...)

|||

your select statement is write

for output:

you can format it inside the program

like that

duppose you put the artikel.lfdnr in x1 and artikel.artnr1 in x2 and arteinordnung.einordnung in x3

s= "4 10000000 "

if (x1=4 and x2= 10000000)

S=S+x3

|||

Ok, so instead of the creation process via "CREATE table #data" I'd let run my standard SQL SELECT. Then I've got all the possible values within the output table. Then I encounter this problem:

Code Snippet

;With CTE

as

(

Select Col1,Col2,Col3,Row_Number() Over (Partition By Col1,Col2 Order By Col1,Col2) Rowid From #Data

)

Select * From CTE

Pivot

(

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

) as Pvt

It looks like I need to know all the possible values for this part, or am I wrong:

Code Snippet

Max(Col3) For Rowid in ([1],[2],[3],[4],[5]) --,...[n])

|||

Code Snippet

create function dbo.MultiList ( @.col1 as int, @.col2 as int )

returns varchar(8000)

as

begin

declare @.list varchar(8000)

select @.list = coalesce( @.list + ', ', '') + Col3

from data where Col1 = @.col1 and Col2 = @.col2

return @.list

end

GO

Create Table data (

[Col1] int ,

[Col2] int ,

[Col3] varchar(20)

);

Insert Into data Values('4','10000000','Juice');

Insert Into data Values('4','10000000','Coca-Cola');

Insert Into data Values('4','10000000','Orange');

Insert Into data Values('4','10000000','Walmart');

Insert Into data Values('5','10000000','Juice');

Insert Into data Values('5','10000000','Coca-Cola');

Insert Into data Values('5','10000000','Orange');

select col1, col2, dbo.MultiList(col1, col2) as items

from data

group by col1, col2

|||

Mh, maybe you're right. I am really struggling in setting up the correct SQL-statement...

At the moment I don't see the possibility to adapt the pivot-function to my SQL-statement.

|||

Rather than the CTE, you may be better served by examining the 'MultiList' function that DaleJ offered.

|||

The multilist function is completely new to me. How do I approach it at best?

To understand the functionality better I'd like to execute my standard SELECT, then I got all the relevant data within a table. Is it possible to skip this procedure in your multilist function, or do I need to set it up like that?

Code Snippet

Create Table data (

[Col1] int ,

[Col2] int ,

[Col3] varchar(20)

);

Somehow I feel not comfortable with the "INSERT INTO ... VALUES (..., ..., ...)" command. It implies that I have to add once all possible list-entries, am I wrong?

|||

Somehow I feel not comfortable with the "INSERT INTO ... VALUES (..., ..., ...)" command. It implies that I have to add once all possible list-entries, am I wrong?

Yes, you are wrong about that. In the previous posting, a sample table was created and it was populated with sample data. You DO NOT USE THE SAMPLE DATA -you use your own table and column names, following the example.

Create the MultiList function in your database, and then execute your 'standard SELECT' -carefully following the example.

|||

I think the way I'd like to format the data is a bit off... I just took a look at the raw data, and it appears to me that the problem isn't as complicated as I thought.

Table1 has a Parent-Child-hierarchy structure... Table2 connects Table1 and the Article_Table via the 'ArtNr'.

Code Snippet

Table1:

LfdNr Kriterium Einordnung

0 1 Marke

0 2 Markenhauptgruppe

0 3 Markenuntergruppe

1 1 Eigenmarke

2 1 Fremdmarke

2 2 Frische

2 3 Valensina

3 2 Handelsmarke

3 3 Chiquita

4 2 Paradise

4 3 Rio Doro

5 2 Lizenzmarke

5 3 Hitchcock

...

Code Snippet

Table2:

ArtNr LfdNr Kriterium

4711 2 1

4711 3 2

4711 4 3

5000 1 1

5000 2 2

...

The Output table should look like this:

Code Snippet

Desired Output:

ArtNr Marke Markenhauptgruppe Markenuntergruppe

4711 Fremdmarke Handelsmarke Rio Doro

5000 Eigenmarke Frische

|||

here it is, (replace the #table1 & #tabl2 with your orginal table name on the Sql Server 2000 & 2005 query)

Code Snippet

Create Table #table1 (

[LfdNr] int ,

[Kriterium] int ,

[Einordnung] Varchar(100)

);

Insert Into #table1 Values('0','1','Marke');

Insert Into #table1 Values('0','2','Markenhauptgruppe');

Insert Into #table1 Values('0','3','Markenuntergruppe');

Insert Into #table1 Values('1','1','Eigenmarke');

Insert Into #table1 Values('2','1','Fremdmarke');

Insert Into #table1 Values('2','2','Frische');

Insert Into #table1 Values('2','3','Valensina');

Insert Into #table1 Values('3','2','Handelsmarke');

Insert Into #table1 Values('3','3','Chiquita');

Insert Into #table1 Values('4','2','Paradise');

Insert Into #table1 Values('4','3','Rio Doro');

Insert Into #table1 Values('5','2','Lizenzmarke');

Insert Into #table1 Values('5','3','Hitchcock');

Create Table #table2 (

[ArtNr] Varchar(100) ,

[LfdNr] int ,

[Kriterium] int

);

Insert Into #table2 Values('4711','2','1');

Insert Into #table2 Values('4711','3','2');

Insert Into #table2 Values('4711','4','3');

Insert Into #table2 Values('5000','1','1');

Insert Into #table2 Values('5000','2','2');

Code Snippet

--SQL Server 2000

Select

[ArtNr]

,[Einordnung]

into #Temp

from

#table2 A

Join #table1 B on

A.[LfdNr]=B.[LfdNr]

And A.[Kriterium] = B.[Kriterium]

Order By

1,2

Alter table #Temp Add RowId int identity(1,1), GroupId int

Update #Temp

Set

GroupId = RowId - (Select Min(RowId) -1 From #Temp Sub Where Sub.[ArtNr] = #Temp.[ArtNr])

select

[ArtNr]

,Isnull(Max(Case When GroupId = 1 Then [Einordnung] End),'') as [Marke]

,Isnull(Max(Case When GroupId = 2 Then [Einordnung] End),'') as [Markenhauptgruppe]

,Isnull(Max(Case When GroupId = 3 Then [Einordnung] End),'') as [Markenuntergruppe]

from

#temp

Group By

[ArtNr]

Code Snippet

--SQL Server 2005

;With CTE

as

(

Select

[ArtNr]

,[Einordnung]

,Row_Number() Over (Partition By [ArtNr] Order By [ArtNr]) GroupId

from

#table2 A

Join #table1 B on

A.[LfdNr]=B.[LfdNr]

And A.[Kriterium] = B.[Kriterium]

)

Select

[ArtNr]

,Isnull([1] ,'') as [Marke]

,Isnull([2] ,'') as [Markenhauptgruppe]

,Isnull([3] ,'') as [Markenuntergruppe]

from

CTE

Pivot

(

Max([Einordnung]) For GroupId in ([1],[2],[3])

) Pvt

|||

Awesome, this is it! Many thanks! But I've got another problem:

(SSMS marks the '(' near PVT as Error?)

Meldung 102, Ebene 15, Status 1, Zeile 21

Falsche Syntax in der N?he von '('.

in english: ;-)

Message 102, Level 15, Status 1, Row 21

False Syntax near '('.

I don't know exactly what's wrong with the statement, to me it seems fine...

|||anyone?

Problems with SQL Server connection string

I am slightly confused about SQL Server connections strings. When I used the following connection string:

string strConn = "server=decius\awa;database=xxxx;uid=xxxx;pwd=xxxx";

I get an error saying "Format of the initialization string does not conform to specification starting at index 13. "

I spent ages trying to figure out why this was and I eventually discovered that adding an "@." symbol before the string fixed it, i.e.

string strConn = @."server=decius\awa;database=xxxx;uid=xxxx;pwd=xxxx";

Most of the examples I have seen to not use the "@." symbol so I am just wondering what is does and when you need to use it?

Thanks,

Mark

The @. fixed your problem because it designates a literal string. Basically, when the processor sees @. before the string it knows to ignore all special characters within that string that would otherwise need to be used with an escape character. In C#, the '\' is an escape character that means 'do not read the following character as a special character. It would be used like so:

string path = "files\\filename.doc";

That will read to the processor as 'files\filename.doc";

As you've found out, you can also use the @. for the same result. These next 2 strings will have the same output:

string path = "files\\filename.doc";

string path = @."files\filename.doc";

...Hope that helps.

|||

Thanks Stew, that's great.

Mark

sql

Monday, March 26, 2012

Problems with SQL Installation when certificate is installed

Hi,
I am trying to setup SQL Server on a machine with a certificate. During the
installation I get the following error:
[Microsoft][ODBC SQL Server Driver][Shared Memory]SSL Security e
rror
[Microsoft][ODBC SQL Server Driver][Shared Memory]ConnectionOpen
(SECDoClientHandshake()).
SQL Server configuration failed.
Now, I know that this is a problem with SQL Server and has been documented
in KB309398
http://support.microsoft.com/defaul...kb;EN-US;309398
But the solution that it suggests involves removing of the certificate and
then installing SQL and Service pack.
The certificate that I have installed has a private key and cannot be fully
exported to a file.
So I cannot delete the certificate.
Is there any alternative way to disable certificates during installation or
any way of installing SQL on a machine with a certificate.
Thanks in advanceAre you running SQL 2000 sp3?
Use the Client Network Utility and Disable or Uncheck Shared Memory.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.

Problems with some characters

Hello
Other than the following character:' are there ay other character that may
cause a problem in SQL Server specifically invisible characters?
Thank you,
Shmuel Shulman
SBS Technologies LTD (UK)I can't think of any other characters but to use ' in SQL you replace
it with '' ( two single quotes)
HTH
Barry
E.g
Declare @.String Varchar(10)
Set @.String = 'O''Connor'
Select @.String|||Hi Barry,
I found te error and it is not related tot he characters.
Cheers,
Shmuel
"Barry" <barry.oconnor@.singers.co.im> wrote in message
news:1127320271.395799.121730@.z14g2000cwz.googlegroups.com...
>I can't think of any other characters but to use ' in SQL you replace
> it with '' ( two single quotes)
> HTH
> Barry
> E.g
> Declare @.String Varchar(10)
> Set @.String = 'O''Connor'
> Select @.String
>|||What Error?sql

Friday, March 23, 2012

Problems with replication across trusted domains

Hi
We have at the following setup:
Windows NT domain 'domainX':
Server A running Win2000 with SQL2000 - publisher
Server B running WinNT4 with SQL2000 - publisher
Windows 2000 Active Directory domain 'domainZ':
Server C running Win2000 with SQ2000 - subscriber
We have established two-way trust between the two
domains. Server B will replicate no problem over to the
subscriber server C. However, when I try to set up server
A to replicate to server C I get the following when I try
to pull the subscription:
SQL Server Enterprise Manager could not retrieve
information about the publication from publisher 'server
A'.
Error 8198 Could not obtain information about Windows NT
group/user 'domainZ\sqlservice'
Both servers are set up with identical sqlservice accounts
to run SQL server and sqlserveragent - as per the rules
for trusted domains.
Any suggestions about how to sort this would be gratefully
received !
Thanks
Stephen ,
there is a good article about troubleshooting these errors:
http://support.microsoft.com/?kbid=834124 .
If you try the recommended solutions and have no success there is a known
issue and hotfix available:
http://support.microsoft.com/default.aspx?kbid=830596.
HTH,
Paul Ibison
|||what happens if you use a local account for the SQL Server agent which has
the same account name and password on both servers (Server A and Server C)?
Also are you using SQL Authentication or NT Authentication?
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Stephen Fleming" <anonymous@.discussions.microsoft.com> wrote in message
news:1f0001c47c89$ab2b6c50$a601280a@.phx.gbl...
> Hi
> We have at the following setup:
> Windows NT domain 'domainX':
> Server A running Win2000 with SQL2000 - publisher
> Server B running WinNT4 with SQL2000 - publisher
> Windows 2000 Active Directory domain 'domainZ':
> Server C running Win2000 with SQ2000 - subscriber
> We have established two-way trust between the two
> domains. Server B will replicate no problem over to the
> subscriber server C. However, when I try to set up server
> A to replicate to server C I get the following when I try
> to pull the subscription:
> SQL Server Enterprise Manager could not retrieve
> information about the publication from publisher 'server
> A'.
> Error 8198 Could not obtain information about Windows NT
> group/user 'domainZ\sqlservice'
> Both servers are set up with identical sqlservice accounts
> to run SQL server and sqlserveragent - as per the rules
> for trusted domains.
> Any suggestions about how to sort this would be gratefully
> received !
> Thanks
|||Hi Hilary
I'll try using a local account for SQL Server Agent and
see what happens - at the moment it's using domain
accounts at both ends. Is the local account method the
preferred option?
Stephen

>--Original Message--
>what happens if you use a local account for the SQL
Server agent which has
>the same account name and password on both servers
(Server A and Server C)?
>Also are you using SQL Authentication or NT
Authentication?
>--
>Hilary Cotter
>Looking for a book on SQL Server replication?
>http://www.nwsu.com/0974973602.html
>
>"Stephen Fleming" <anonymous@.discussions.microsoft.com>
wrote in message[vbcol=seagreen]
>news:1f0001c47c89$ab2b6c50$a601280a@.phx.gbl...
the[vbcol=seagreen]
server[vbcol=seagreen]
try[vbcol=seagreen]
publisher 'server[vbcol=seagreen]
NT[vbcol=seagreen]
accounts[vbcol=seagreen]
gratefully
>
>.
>
|||It depends. What is important if that your pull susbcriber must be able to
access the snapshot share on the publisher or distributor.
If you are in an untrusted domain you will have to use passthrough
authentication to get this to work, and you may have to craft a snapshot
share that this account can access.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
<anonymous@.discussions.microsoft.com> wrote in message
news:2a0901c47e10$3f47c0a0$a501280a@.phx.gbl...[vbcol=seagreen]
> Hi Hilary
> I'll try using a local account for SQL Server Agent and
> see what happens - at the moment it's using domain
> accounts at both ends. Is the local account method the
> preferred option?
> Stephen
> Server agent which has
> (Server A and Server C)?
> Authentication?
> wrote in message
> the
> server
> try
> publisher 'server
> NT
> accounts
> gratefully

Problems with quick record count (no table info in sysindexes)

Hi everybody,
In my program, I use the following statement to get a quick count of the
records in a given table:
SELECT [rows] FROM sysindexes WHERE [indid] = 0 AND [name] = 'table_name'
I don't know if it's just a bug with SQL, but it sometimes happens that when
there are changes to a particular table, there is no entry for that table in
sysindexes. I know this is pretty weird because BOL states that every table
should have an entry in sysindexes. If I drop the DB and then recreate it,
everything's OK but this is, of course, no realistic solution every time I
alter a table.
Does anyone else have this problem? Is there anything I can run to
repopulate sysindexes? Was this solved with some SP?
Any help would be much appreciated.
TIA,
sivrik.> In my program, I use the following statement to get a quick count of the
> records in a given table:
Why not just to SELECT COUNT(*) FROM TableName
or look at sp_spaceused system stored procedure in the BOL
Note: It's not recomended to query system tables instead use
INFORMATION_SCHEMA views. (See examples in the BOL)
"sivrik" <sivrik@.discussions.microsoft.com> wrote in message
news:7BB560F0-ADB7-43CB-B0FA-8BD687F65699@.microsoft.com...
> Hi everybody,
> In my program, I use the following statement to get a quick count of the
> records in a given table:
> SELECT [rows] FROM sysindexes WHERE [indid] = 0 AND [name] = 'table_name'
> I don't know if it's just a bug with SQL, but it sometimes happens that
when
> there are changes to a particular table, there is no entry for that table
in
> sysindexes. I know this is pretty weird because BOL states that every
table
> should have an entry in sysindexes. If I drop the DB and then recreate
it,
> everything's OK but this is, of course, no realistic solution every time I
> alter a table.
> Does anyone else have this problem? Is there anything I can run to
> repopulate sysindexes? Was this solved with some SP?
> Any help would be much appreciated.
> TIA,
> sivrik.|||Uri,
Thanks for the reply. I don't use SELECT COUNT(*) because there can be a
lot of data in a particular table and it takes forever. Thanks for the tip
on sp_spaceused. Is there a way to get it to return only the rowcount? I
need to set the value to a variable. I know this won't work but something
like:
select [rows] from (exec sp_spaceused 'table_name')
Or maybe there's another way to get this value quickly. I took a quick look
at INFORMATION_SCHEMA but couldn't find anything helpful.
Thanks again,
sivrik.
"Uri Dimant" wrote:

> Why not just to SELECT COUNT(*) FROM TableName
> or look at sp_spaceused system stored procedure in the BOL
>
> Note: It's not recomended to query system tables instead use
> INFORMATION_SCHEMA views. (See examples in the BOL)
>
> "sivrik" <sivrik@.discussions.microsoft.com> wrote in message
> news:7BB560F0-ADB7-43CB-B0FA-8BD687F65699@.microsoft.com...
> when
> in
> table
> it,
>
>|||I think your problem is that you are assuming that indid is always the table
.
If the table has a clustered index, then the 0 is changed to 1. 0 for indid
indicates the table has no clustered index and is a heap. When a clustered
index is added the 0 is changed.
select count(*) is the best way to get a quick count of rows. I uses index
information if possible.
"sivrik" wrote:

> Hi everybody,
> In my program, I use the following statement to get a quick count of the
> records in a given table:
> SELECT [rows] FROM sysindexes WHERE [indid] = 0 AND [name] = 'table_name'
> I don't know if it's just a bug with SQL, but it sometimes happens that wh
en
> there are changes to a particular table, there is no entry for that table
in
> sysindexes. I know this is pretty weird because BOL states that every tab
le
> should have an entry in sysindexes. If I drop the DB and then recreate it
,
> everything's OK but this is, of course, no realistic solution every time I
> alter a table.
> Does anyone else have this problem? Is there anything I can run to
> repopulate sysindexes? Was this solved with some SP?
> Any help would be much appreciated.
> TIA,
> sivrik.|||Mike,
Thanks for the reply. I did make that assumption but the problem is that
ALL information for the particular table "disappears" from sysindexes. So
SELECT * FROM sysindexes WHERE [name] = 'Table_Name'
returns absolutely nothing. SELECT COUNT(*) from a table with a lot of data
in it takes forever so that's why I was looking for a quicker way.
sivrik.
"Mike Hanson" wrote:
> I think your problem is that you are assuming that indid is always the tab
le.
> If the table has a clustered index, then the 0 is changed to 1. 0 for ind
id
> indicates the table has no clustered index and is a heap. When a clustere
d
> index is added the 0 is changed.
> select count(*) is the best way to get a quick count of rows. I uses inde
x
> information if possible.
> "sivrik" wrote:
>|||Hi
You will have to create a 'template' table with all columns that output from
sp_spaceused
INSERT INTO #Temp EXEC sp_spaceused 'table name'
SELECT COUNT(rows) FROM #Temp
Another way is to create an indexed view that will produce a more efficient
execution plan.
This example has written by Steve Kass.
create table T (
i int,
filler char(1000) default 'abc'
)
go
create view T_count with schemabinding as
select
cast(i as bit) as val,
count_big(*) T_count
from dbo.T group by cast(i as bit)
go
create unique clustered index T_count_uci on T_count(val)
go
insert into T(i)
select OrderID
from Northwind..[Order Details]
go
set statistics io on
select count(*) from T
go
select sum(T_count) from T_count with (noexpand)
go
set statistics io off
-- uses an efficient query plan on the materialized view
go
drop view T_count
drop table T
"sivrik" <sivrik@.discussions.microsoft.com> wrote in message
news:0F09E3E7-2B20-41BD-98E6-0354136D8D2C@.microsoft.com...
> Uri,
> Thanks for the reply. I don't use SELECT COUNT(*) because there can be a
> lot of data in a particular table and it takes forever. Thanks for the
tip
> on sp_spaceused. Is there a way to get it to return only the rowcount? I
> need to set the value to a variable. I know this won't work but something
> like:
> select [rows] from (exec sp_spaceused 'table_name')
> Or maybe there's another way to get this value quickly. I took a quick
look
> at INFORMATION_SCHEMA but couldn't find anything helpful.
> Thanks again,
> sivrik.
> "Uri Dimant" wrote:
>
the
the
'table_name'
that
table
recreate
time I|||Hi Sivrik
I have never heard of information dissappearing from sysindexes before, at
the risk of offending you, are you sure you are running the select within th
e
right database context. I do this all the time in Query Analyzer, forgettin
g
to change the context, perhaps your application connection string is not
setting the correct database context for the query.
I usally find count(*) to be quite fast if a clustered index exists on the
table and statistics are up to date. Usually slow performance of this
function means it is actually having to update the statistics (if automatic
statistics are enabled) or do a manual count, because statistics are out of
date or do not exist.
Mike Hanson
"sivrik" wrote:
> Mike,
> Thanks for the reply. I did make that assumption but the problem is that
> ALL information for the particular table "disappears" from sysindexes. So
> SELECT * FROM sysindexes WHERE [name] = 'Table_Name'
> returns absolutely nothing. SELECT COUNT(*) from a table with a lot of da
ta
> in it takes forever so that's why I was looking for a quicker way.
> sivrik.
>
> "Mike Hanson" wrote:
>|||sivrik try
create table #temp(name varchar(100), rows int, reserved varchar(100), data
varchar(100), index_size varchar(100), unused varchar(100))
insert #temp(name, rows, reserved, data, index_size, unused)
exec sp_spaceused 'your table'
select rows from #temp
Regards
Meir
"sivrik" <sivrik@.discussions.microsoft.com> wrote in message
news:0F09E3E7-2B20-41BD-98E6-0354136D8D2C@.microsoft.com...
> Uri,
> Thanks for the reply. I don't use SELECT COUNT(*) because there can be a
> lot of data in a particular table and it takes forever. Thanks for the
tip
> on sp_spaceused. Is there a way to get it to return only the rowcount? I
> need to set the value to a variable. I know this won't work but something
> like:
> select [rows] from (exec sp_spaceused 'table_name')
> Or maybe there's another way to get this value quickly. I took a quick
look
> at INFORMATION_SCHEMA but couldn't find anything helpful.
> Thanks again,
> sivrik.
> "Uri Dimant" wrote:
>
the
the
'table_name'
that
table
recreate
time I|||No offense taken, I'm sure we've all forgot to swith the DB in query analyze
r
before. =) No, it's not that I'm running it in the wrong context. It's
actually that there is no more information about the table in sysindexes. I
t
seems strange to me too so that's why I was asking.
Thanks,
sivrik.
"Mike Hanson" wrote:

> Hi Sivrik
> I have never heard of information dissappearing from sysindexes before, at
> the risk of offending you, are you sure you are running the select within
the
> right database context. I do this all the time in Query Analyzer, forgett
ing
> to change the context, perhaps your application connection string is not
> setting the correct database context for the query.
> I usally find count(*) to be quite fast if a clustered index exists on the
> table and statistics are up to date. Usually slow performance of this
> function means it is actually having to update the statistics (if automati
c
> statistics are enabled) or do a manual count, because statistics are out o
f
> date or do not exist.
> Mike Hanson
>|||Also you need to be aware that the information you get from spaceused (which
comes from sysindexes ) is not updated with each insert, update, or delete,
and will often be close , but not exact... ( It can be very far off if you
have done a truncate table.)
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"sivrik" <sivrik@.discussions.microsoft.com> wrote in message
news:B7F509C2-6C9E-4B0B-B091-0A8DFBB8F790@.microsoft.com...
> No offense taken, I'm sure we've all forgot to swith the DB in query
> analyzer
> before. =) No, it's not that I'm running it in the wrong context. It's
> actually that there is no more information about the table in sysindexes.
> It
> seems strange to me too so that's why I was asking.
> Thanks,
> sivrik.
> "Mike Hanson" wrote:
>
>

Problems with queries on Win 2003 server

I am running into lot of problems with queries when
I run it on a windows 2003 server having Sql 2000 SP3A
pack.
I was able to run the following query just fine on
Windows NT with Sql 7 -
SELECT filing_area, File_num, contract_num, * from
eng_file where filing_area+ COALESCE(file_num, 'TEST') +
COALESCE(contract_num, 'TEST')
in (select filing_area + COALESCE(file_num, 'TEST') +
COALESCE(contract_num, 'TEST') from eng_file
group by filing_area + COALESCE(file_num, 'TEST') +
COALESCE(contract_num, 'TEST') having count(*) > 1 )
But the same query gives me the following errors
when run on Win 2003 with Sql 2000 SP3 or Win 2k with Sql
2k sp3.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'eng_file.FILING_AREA' is invalid in the select
list because it is not contained in either an aggregate
function or the GROUP BY clause.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'eng_file.FILE_NUM' is invalid in the select list
because it is not contained in either an aggregate
function or the GROUP BY clause.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'eng_file.FILE_NUM' is invalid in the select list
because it is not contained in either an aggregate
function or the GROUP BY clause.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'eng_file.CONTRACT_NUM' is invalid in the select
list because it is not contained in either an aggregate
function or the GROUP BY clause.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'eng_file.CONTRACT_NUM' is invalid in the select
list because it is not contained in either an aggregate
function or the GROUP BY clause.
What I am missing?
Thank you,
-LiThe behaviour of queries with expressions in the GROUP BY list doesn't
always seem very logical. I don't have 7.0 to verify but the following query
should work on both versions. In your IN comparison, notice that (a1+b1+c1 =a2+b2+c2) is NOT the same comparison as (a1=a2, b1=b2, c1=c2) if these
values are variable-lengths strings. Unless the strings are CHAR or VARCHAR
of equal length then the result of your query may not be what I think you
intended.
SELECT T1.filing_area, T1.file_num, T1.contract_num, *
FROM eng_file AS T1
JOIN
(SELECT filing_area,
COALESCE(file_num, 'TEST'),
COALESCE(contract_num, 'TEST')
FROM eng_file
GROUP BY filing_area,
COALESCE(file_num, 'TEST'),
COALESCE(contract_num, 'TEST')
HAVING COUNT(*)>1)
AS T2(filing_area, file_num, contract_num)
ON T1.filing_area = T2.filing_area
AND COALESCE(T1.file_num, 'TEST') = T2.file_num
AND COALESCE(T1.contract_num, 'TEST') = T2.contract_num
--
David Portas
SQL Server MVP
--|||Your original query works on SQL Server 2005 (9.00.852), so although it
doesn't help you now it does appear that the problem has been fixed. :-)
--
David Portas
SQL Server MVP
--|||Li,
This certainly looks like a bug to me. I believe your query will
succeed if you replace COALESCE by ISNULL. The two functions are not
identical, however. The data type of COALESCE(x,y) accommodates all
the arguments, but the type of ISNULL(x,y) is the type of x. Also,
COALESCE takes multiple arguments and ISNULL must be nested.
I'll pass this on to Microsoft, since I have not seen it reported
before. Thanks!
Steve Kass
Drew University
Li wrote:
>I am running into lot of problems with queries when
>I run it on a windows 2003 server having Sql 2000 SP3A
>pack.
>I was able to run the following query just fine on
>Windows NT with Sql 7 -
>SELECT filing_area, File_num, contract_num, * from
>eng_file where filing_area+ COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST')
>in (select filing_area + COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST') from eng_file
>group by filing_area + COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST') having count(*) > 1 )
>But the same query gives me the following errors
>when run on Win 2003 with Sql 2000 SP3 or Win 2k with Sql
>2k sp3.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILING_AREA' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILE_NUM' is invalid in the select list
>because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILE_NUM' is invalid in the select list
>because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>
>What I am missing?
>Thank you,
>-Li
>
>|||Li,
A better workaround (I only checked a simpler query) is to replace
COALESCE(x,y) with CASE WHEN x IS NULL THEN x ELSE y END, which is
equivalent. I think the bug here is a parsing problem that comes up if
a subquery groups on a CASE WHEN NOT ... expression, which is how the
COALESCE must be getting rewritten.
SK
Li wrote:
>I am running into lot of problems with queries when
>I run it on a windows 2003 server having Sql 2000 SP3A
>pack.
>I was able to run the following query just fine on
>Windows NT with Sql 7 -
>SELECT filing_area, File_num, contract_num, * from
>eng_file where filing_area+ COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST')
>in (select filing_area + COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST') from eng_file
>group by filing_area + COALESCE(file_num, 'TEST') +
>COALESCE(contract_num, 'TEST') having count(*) > 1 )
>But the same query gives me the following errors
>when run on Win 2003 with Sql 2000 SP3 or Win 2k with Sql
>2k sp3.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILING_AREA' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILE_NUM' is invalid in the select list
>because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.FILE_NUM' is invalid in the select list
>because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>Server: Msg 8120, Level 16, State 1, Line 1
>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>list because it is not contained in either an aggregate
>function or the GROUP BY clause.
>
>What I am missing?
>Thank you,
>-Li
>
>|||Li,
ISNUll worked - thank you.
Please do let me know if you get a chance to report
this to Microsoft and their reaction to it.
Thank you,
-Li
>--Original Message--
>Li,
> This certainly looks like a bug to me. I believe your
query will
>succeed if you replace COALESCE by ISNULL. The two
functions are not
>identical, however. The data type of COALESCE(x,y)
accommodates all
>the arguments, but the type of ISNULL(x,y) is the type
of x. Also,
>COALESCE takes multiple arguments and ISNULL must be
nested.
> I'll pass this on to Microsoft, since I have not seen
it reported
>before. Thanks!
>Steve Kass
>Drew University
>Li wrote:
>>I am running into lot of problems with queries when
>>I run it on a windows 2003 server having Sql 2000 SP3A
>>pack.
>>I was able to run the following query just fine on
>>Windows NT with Sql 7 -
>>SELECT filing_area, File_num, contract_num, * from
>>eng_file where filing_area+ COALESCE(file_num, 'TEST')
+
>>COALESCE(contract_num, 'TEST')
>>in (select filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') from eng_file
>>group by filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') having count(*) > 1 )
>>But the same query gives me the following errors
>>when run on Win 2003 with Sql 2000 SP3 or Win 2k with
Sql
>>2k sp3.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILING_AREA' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>
>>What I am missing?
>>Thank you,
>>-Li
>>
>.
>|||Steve,
I agree the query may not be the best one as it was
written to quickly take care of some data issues we are
facing and came up with this. Since it worked fine on Sql
7.0, I don't find any reason for it not to work with Sql
2K. David mentioned that it works on Sql 2k so the
problem may have been fixed. What am I missing that it
isn't working for me?
Any ideas?
I am going to write to David too.
Thank you very much for yout time and input -
-Li
>--Original Message--
>Li,
> A better workaround (I only checked a simpler query)
is to replace
>COALESCE(x,y) with CASE WHEN x IS NULL THEN x ELSE y
END, which is
>equivalent. I think the bug here is a parsing problem
that comes up if
>a subquery groups on a CASE WHEN NOT ... expression,
which is how the
>COALESCE must be getting rewritten.
>SK
>Li wrote:
>>I am running into lot of problems with queries when
>>I run it on a windows 2003 server having Sql 2000 SP3A
>>pack.
>>I was able to run the following query just fine on
>>Windows NT with Sql 7 -
>>SELECT filing_area, File_num, contract_num, * from
>>eng_file where filing_area+ COALESCE(file_num, 'TEST')
+
>>COALESCE(contract_num, 'TEST')
>>in (select filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') from eng_file
>>group by filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') having count(*) > 1 )
>>But the same query gives me the following errors
>>when run on Win 2003 with Sql 2000 SP3 or Win 2k with
Sql
>>2k sp3.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILING_AREA' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>
>>What I am missing?
>>Thank you,
>>-Li
>>
>.
>|||Steve,
Ignore my comments about why it isn't working for me.
When I went to reply to DAvid's email, I noticed that he
said it is fixed on 2005 and not 2000, that answers my
question.
-Li
>--Original Message--
>Li,
> A better workaround (I only checked a simpler query)
is to replace
>COALESCE(x,y) with CASE WHEN x IS NULL THEN x ELSE y
END, which is
>equivalent. I think the bug here is a parsing problem
that comes up if
>a subquery groups on a CASE WHEN NOT ... expression,
which is how the
>COALESCE must be getting rewritten.
>SK
>Li wrote:
>>I am running into lot of problems with queries when
>>I run it on a windows 2003 server having Sql 2000 SP3A
>>pack.
>>I was able to run the following query just fine on
>>Windows NT with Sql 7 -
>>SELECT filing_area, File_num, contract_num, * from
>>eng_file where filing_area+ COALESCE(file_num, 'TEST')
+
>>COALESCE(contract_num, 'TEST')
>>in (select filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') from eng_file
>>group by filing_area + COALESCE(file_num, 'TEST') +
>>COALESCE(contract_num, 'TEST') having count(*) > 1 )
>>But the same query gives me the following errors
>>when run on Win 2003 with Sql 2000 SP3 or Win 2k with
Sql
>>2k sp3.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILING_AREA' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.FILE_NUM' is invalid in the select
list
>>because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>Server: Msg 8120, Level 16, State 1, Line 1
>>Column 'eng_file.CONTRACT_NUM' is invalid in the select
>>list because it is not contained in either an aggregate
>>function or the GROUP BY clause.
>>
>>What I am missing?
>>Thank you,
>>-Li
>>
>.
>sql