Friday, March 30, 2012

help out of control query

Hi,
I jsut had a big problem, a table of 15000 was updated on 10000 for a
bit changed to true and all the record show the same datetime for the
change, the only query how can do this change is this :
/**
CREATE PROCEDURE OdM1
@.InvoicesPassID [numeric]
AS
update InvoicesPassive
set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
where ID=@.InvoicesPassID
/**
How this query can do that ?
Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
Thanks for any suggestion.
Paolol
Only the affected rows should reflect the new datetime.
jens Suessmeyer.
|||Hi
Can you show us a table structure and how do you assign a parameter to the
SP?
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
> changed to true and all the record show the same datetime for the change,
> the only query how can do this change is this :
> /**
> CREATE PROCEDURE OdM1
> @.InvoicesPassID [numeric]
> AS
> update InvoicesPassive
> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
> where ID=@.InvoicesPassID
> /**
> How this query can do that ?
> Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
> Thanks for any suggestion.
> Paolol
|||Uri Dimant ha scritto:
> Hi
> Can you show us a table structure and how do you assign a parameter to the
> SP?
>
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>
>
Hi NP
/** TABLE
[ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[SitesID] [numeric](18, 0) NOT NULL ,
[CompanyID] [numeric](18, 0) NOT NULL ,
[Via] [numeric](18, 0) NOT NULL ,
[Deleted] [bit] NOT NULL ,
[Void] [bit] NOT NULL ,
[CheckSigla] [bit] NOT NULL ,
[UserIDIN] [numeric](18, 0) NOT NULL ,
[UserIDMOD] [numeric](18, 0) NOT NULL ,
[DataIN] [datetime] NOT NULL ,
[DataMod] [datetime] NOT NULL ,
[VendorID] [numeric](18, 0) NOT NULL ,
[VendorIDD] [numeric](18, 0) NOT NULL ,
[InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT
NULL ,
[InvoiceDate] [datetime] NOT NULL ,
[TotImponibile] [float] NOT NULL ,
[TotIva] [float] NOT NULL ,
[TotInvoice] [float] NOT NULL ,
[TotImponibileF] [float] NOT NULL ,
[TotIvaF] [float] NOT NULL ,
[TotInvoiceF] [float] NOT NULL ,
[CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[InvoiceToCheck] [float] NOT NULL ,
[VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[VendorType] [numeric](18, 0) NOT NULL ,
[TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Checked] [bit] NOT NULL ,
[NotaCredito] [bit] NOT NULL ,
[AutoFattura] [bit] NOT NULL ,
[WhoDeleted] [numeric](18, 0) NOT NULL ,
[DataDeleted] [datetime] NOT NULL ,
[PaymentTermsID] [numeric](18, 0) NOT NULL
/**
from program is
"execute ODM1 iID "
iID is the numeric for the record ID and goes by adoQuery
Thanks,
Paolol
|||Hi
Well ,looks strange.Do you have any triggers defined on the table?
create table #test
(
col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
col2 char(1)
)
insert into #test (col2) values ('a')
insert into #test (col2)values ('b')
insert into #test (col2) values ('c')
select * from #test
declare @.p numeric
set @.p=1
update #test set col2 ='g' where col1=@.p.
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
> Uri Dimant ha scritto:
> Hi NP
> /** TABLE
> [ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> [SitesID] [numeric](18, 0) NOT NULL ,
> [CompanyID] [numeric](18, 0) NOT NULL ,
> [Via] [numeric](18, 0) NOT NULL ,
> [Deleted] [bit] NOT NULL ,
> [Void] [bit] NOT NULL ,
> [CheckSigla] [bit] NOT NULL ,
> [UserIDIN] [numeric](18, 0) NOT NULL ,
> [UserIDMOD] [numeric](18, 0) NOT NULL ,
> [DataIN] [datetime] NOT NULL ,
> [DataMod] [datetime] NOT NULL ,
> [VendorID] [numeric](18, 0) NOT NULL ,
> [VendorIDD] [numeric](18, 0) NOT NULL ,
> [InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT
> NULL ,
> [InvoiceDate] [datetime] NOT NULL ,
> [TotImponibile] [float] NOT NULL ,
> [TotIva] [float] NOT NULL ,
> [TotInvoice] [float] NOT NULL ,
> [TotImponibileF] [float] NOT NULL ,
> [TotIvaF] [float] NOT NULL ,
> [TotInvoiceF] [float] NOT NULL ,
> [CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [InvoiceToCheck] [float] NOT NULL ,
> [VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [VendorType] [numeric](18, 0) NOT NULL ,
> [TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [Checked] [bit] NOT NULL ,
> [NotaCredito] [bit] NOT NULL ,
> [AutoFattura] [bit] NOT NULL ,
> [WhoDeleted] [numeric](18, 0) NOT NULL ,
> [DataDeleted] [datetime] NOT NULL ,
> [PaymentTermsID] [numeric](18, 0) NOT NULL
> /**
> from program is
> "execute ODM1 iID "
> iID is the numeric for the record ID and goes by adoQuery
> Thanks,
> Paolol
|||Hi Uri,
yes very strange
No no trigger at all, and this procedure is not called by any other, is
a stand alone procedure and the most strange think is the DataDeleted
that is exactly the same for all deleted record !!! up to the millisecond !!
Uri Dimant ha scritto:
> Hi
> Well ,looks strange.Do you have any triggers defined on the table?
>
> create table #test
> (
> col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> col2 char(1)
> )
> insert into #test (col2) values ('a')
> insert into #test (col2)values ('b')
> insert into #test (col2) values ('c')
> select * from #test
> declare @.p numeric
> set @.p=1
> update #test set col2 ='g' where col1=@.p.
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
>
>
|||My guess is that someone executed some other UPDATE or stored procedure to perform this action...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:%23b1zOXWAGHA.3064@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
> Hi Uri,
> yes very strange
> No no trigger at all, and this procedure is not called by any other, is a stand alone procedure
> and the most strange think is the DataDeleted that is exactly the same for all deleted record !!!
> up to the millisecond !!
>
> Uri Dimant ha scritto:

help out of control query

Hi,
I jsut had a big problem, a table of 15000 was updated on 10000 for a
bit changed to true and all the record show the same datetime for the
change, the only query how can do this change is this :
/**
CREATE PROCEDURE OdM1
@.InvoicesPassID [numeric]
AS
update InvoicesPassive
set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
where ID=@.InvoicesPassID
/**
How this query can do that ?
Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
Thanks for any suggestion.
PaololOnly the affected rows should reflect the new datetime.
jens Suessmeyer.|||Hi
Can you show us a table structure and how do you assign a parameter to the
SP?
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
> changed to true and all the record show the same datetime for the change,
> the only query how can do this change is this :
> /**
> CREATE PROCEDURE OdM1
> @.InvoicesPassID [numeric]
> AS
> update InvoicesPassive
> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
> where ID=@.InvoicesPassID
> /**
> How this query can do that ?
> Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
> Thanks for any suggestion.
> Paolol|||Uri Dimant ha scritto:
> Hi
> Can you show us a table structure and how do you assign a parameter to the
> SP?
>
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>>Hi,
>>I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
>>changed to true and all the record show the same datetime for the change,
>>the only query how can do this change is this :
>>/**
>>CREATE PROCEDURE OdM1
>>@.InvoicesPassID [numeric]
>>AS
>> update InvoicesPassive
>> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
>> where ID=@.InvoicesPassID
>>/**
>>How this query can do that ?
>>Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
>>Thanks for any suggestion.
>>Paolol
>
>
Hi NP :)
/** TABLE
[ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[SitesID] [numeric](18, 0) NOT NULL ,
[CompanyID] [numeric](18, 0) NOT NULL ,
[Via] [numeric](18, 0) NOT NULL ,
[Deleted] [bit] NOT NULL ,
[Void] [bit] NOT NULL ,
[CheckSigla] [bit] NOT NULL ,
[UserIDIN] [numeric](18, 0) NOT NULL ,
[UserIDMOD] [numeric](18, 0) NOT NULL ,
[DataIN] [datetime] NOT NULL ,
[DataMod] [datetime] NOT NULL ,
[VendorID] [numeric](18, 0) NOT NULL ,
[VendorIDD] [numeric](18, 0) NOT NULL ,
[InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT
NULL ,
[InvoiceDate] [datetime] NOT NULL ,
[TotImponibile] [float] NOT NULL ,
[TotIva] [float] NOT NULL ,
[TotInvoice] [float] NOT NULL ,
[TotImponibileF] [float] NOT NULL ,
[TotIvaF] [float] NOT NULL ,
[TotInvoiceF] [float] NOT NULL ,
[CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[InvoiceToCheck] [float] NOT NULL ,
[VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[VendorType] [numeric](18, 0) NOT NULL ,
[TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Checked] [bit] NOT NULL ,
[NotaCredito] [bit] NOT NULL ,
[AutoFattura] [bit] NOT NULL ,
[WhoDeleted] [numeric](18, 0) NOT NULL ,
[DataDeleted] [datetime] NOT NULL ,
[PaymentTermsID] [numeric](18, 0) NOT NULL
/**
from program is
"execute ODM1 iID "
iID is the numeric for the record ID and goes by adoQuery
Thanks,
Paolol|||Hi
Well ,looks strange.Do you have any triggers defined on the table?
create table #test
(
col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
col2 char(1)
)
insert into #test (col2) values ('a')
insert into #test (col2)values ('b')
insert into #test (col2) values ('c')
select * from #test
declare @.p numeric
set @.p=1
update #test set col2 ='g' where col1=@.p.
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
> Uri Dimant ha scritto:
>> Hi
>> Can you show us a table structure and how do you assign a parameter to
>> the SP?
>>
>>
>> "paolol" <paolol@._nospamma_salsan.net> wrote in message
>> news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>>Hi,
>>I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
>>changed to true and all the record show the same datetime for the change,
>>the only query how can do this change is this :
>>/**
>>CREATE PROCEDURE OdM1
>>@.InvoicesPassID [numeric]
>>AS
>> update InvoicesPassive
>> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
>> where ID=@.InvoicesPassID
>>/**
>>How this query can do that ?
>>Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
>>Thanks for any suggestion.
>>Paolol
>>
> Hi NP :)
> /** TABLE
> [ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> [SitesID] [numeric](18, 0) NOT NULL ,
> [CompanyID] [numeric](18, 0) NOT NULL ,
> [Via] [numeric](18, 0) NOT NULL ,
> [Deleted] [bit] NOT NULL ,
> [Void] [bit] NOT NULL ,
> [CheckSigla] [bit] NOT NULL ,
> [UserIDIN] [numeric](18, 0) NOT NULL ,
> [UserIDMOD] [numeric](18, 0) NOT NULL ,
> [DataIN] [datetime] NOT NULL ,
> [DataMod] [datetime] NOT NULL ,
> [VendorID] [numeric](18, 0) NOT NULL ,
> [VendorIDD] [numeric](18, 0) NOT NULL ,
> [InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT
> NULL ,
> [InvoiceDate] [datetime] NOT NULL ,
> [TotImponibile] [float] NOT NULL ,
> [TotIva] [float] NOT NULL ,
> [TotInvoice] [float] NOT NULL ,
> [TotImponibileF] [float] NOT NULL ,
> [TotIvaF] [float] NOT NULL ,
> [TotInvoiceF] [float] NOT NULL ,
> [CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [InvoiceToCheck] [float] NOT NULL ,
> [VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
> ,
> [VendorType] [numeric](18, 0) NOT NULL ,
> [TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [Checked] [bit] NOT NULL ,
> [NotaCredito] [bit] NOT NULL ,
> [AutoFattura] [bit] NOT NULL ,
> [WhoDeleted] [numeric](18, 0) NOT NULL ,
> [DataDeleted] [datetime] NOT NULL ,
> [PaymentTermsID] [numeric](18, 0) NOT NULL
> /**
> from program is
> "execute ODM1 iID "
> iID is the numeric for the record ID and goes by adoQuery
> Thanks,
> Paolol|||Hi Uri,
yes very strange :(
No no trigger at all, and this procedure is not called by any other, is
a stand alone procedure and the most strange think is the DataDeleted
that is exactly the same for all deleted record !!! up to the millisecond !!
Uri Dimant ha scritto:
> Hi
> Well ,looks strange.Do you have any triggers defined on the table?
>
> create table #test
> (
> col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> col2 char(1)
> )
> insert into #test (col2) values ('a')
> insert into #test (col2)values ('b')
> insert into #test (col2) values ('c')
> select * from #test
> declare @.p numeric
> set @.p=1
> update #test set col2 ='g' where col1=@.p.
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
>>Uri Dimant ha scritto:
>>Hi
>>Can you show us a table structure and how do you assign a parameter to
>>the SP?
>>
>>
>>"paolol" <paolol@._nospamma_salsan.net> wrote in message
>>news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>>
>>Hi,
>>I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
>>changed to true and all the record show the same datetime for the change,
>>the only query how can do this change is this :
>>/**
>>CREATE PROCEDURE OdM1
>>@.InvoicesPassID [numeric]
>>AS
>>update InvoicesPassive
>> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
>> where ID=@.InvoicesPassID
>>/**
>>How this query can do that ?
>>Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
>>Thanks for any suggestion.
>>Paolol
>>
>>Hi NP :)
>>/** TABLE
>>[ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
>>[SitesID] [numeric](18, 0) NOT NULL ,
>>[CompanyID] [numeric](18, 0) NOT NULL ,
>>[Via] [numeric](18, 0) NOT NULL ,
>>[Deleted] [bit] NOT NULL ,
>>[Void] [bit] NOT NULL ,
>>[CheckSigla] [bit] NOT NULL ,
>>[UserIDIN] [numeric](18, 0) NOT NULL ,
>>[UserIDMOD] [numeric](18, 0) NOT NULL ,
>>[DataIN] [datetime] NOT NULL ,
>>[DataMod] [datetime] NOT NULL ,
>>[VendorID] [numeric](18, 0) NOT NULL ,
>>[VendorIDD] [numeric](18, 0) NOT NULL ,
>>[InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT
>>NULL ,
>>[InvoiceDate] [datetime] NOT NULL ,
>>[TotImponibile] [float] NOT NULL ,
>>[TotIva] [float] NOT NULL ,
>>[TotInvoice] [float] NOT NULL ,
>>[TotImponibileF] [float] NOT NULL ,
>>[TotIvaF] [float] NOT NULL ,
>>[TotInvoiceF] [float] NOT NULL ,
>>[CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
>>,
>>[InvoiceToCheck] [float] NOT NULL ,
>>[VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
>>,
>>[VendorType] [numeric](18, 0) NOT NULL ,
>>[TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>>[Checked] [bit] NOT NULL ,
>>[NotaCredito] [bit] NOT NULL ,
>>[AutoFattura] [bit] NOT NULL ,
>>[WhoDeleted] [numeric](18, 0) NOT NULL ,
>>[DataDeleted] [datetime] NOT NULL ,
>>[PaymentTermsID] [numeric](18, 0) NOT NULL
>>/**
>>from program is
>>"execute ODM1 iID "
>>iID is the numeric for the record ID and goes by adoQuery
>>Thanks,
>>Paolol
>
>|||My guess is that someone executed some other UPDATE or stored procedure to perform this action...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:%23b1zOXWAGHA.3064@.TK2MSFTNGP10.phx.gbl...
> Hi Uri,
> yes very strange :(
> No no trigger at all, and this procedure is not called by any other, is a stand alone procedure
> and the most strange think is the DataDeleted that is exactly the same for all deleted record !!!
> up to the millisecond !!
>
> Uri Dimant ha scritto:
>> Hi
>> Well ,looks strange.Do you have any triggers defined on the table?
>>
>> create table #test
>> (
>> col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
>> col2 char(1)
>> )
>> insert into #test (col2) values ('a')
>> insert into #test (col2)values ('b')
>> insert into #test (col2) values ('c')
>> select * from #test
>> declare @.p numeric
>> set @.p=1
>> update #test set col2 ='g' where col1=@.p.
>>
>> "paolol" <paolol@._nospamma_salsan.net> wrote in message
>> news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
>>Uri Dimant ha scritto:
>>Hi
>>Can you show us a table structure and how do you assign a parameter to the SP?
>>
>>
>>"paolol" <paolol@._nospamma_salsan.net> wrote in message
>>news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>>
>>Hi,
>>I jsut had a big problem, a table of 15000 was updated on 10000 for a bit changed to true and
>>all the record show the same datetime for the change, the only query how can do this change is
>>this :
>>/**
>>CREATE PROCEDURE OdM1
>>@.InvoicesPassID [numeric]
>>AS
>>update InvoicesPassive
>> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
>> where ID=@.InvoicesPassID
>>/**
>>How this query can do that ?
>>Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
>>Thanks for any suggestion.
>>Paolol
>>
>>Hi NP :)
>>/** TABLE
>>[ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
>>[SitesID] [numeric](18, 0) NOT NULL ,
>>[CompanyID] [numeric](18, 0) NOT NULL ,
>>[Via] [numeric](18, 0) NOT NULL ,
>>[Deleted] [bit] NOT NULL ,
>>[Void] [bit] NOT NULL ,
>>[CheckSigla] [bit] NOT NULL ,
>>[UserIDIN] [numeric](18, 0) NOT NULL ,
>>[UserIDMOD] [numeric](18, 0) NOT NULL ,
>>[DataIN] [datetime] NOT NULL ,
>>[DataMod] [datetime] NOT NULL ,
>>[VendorID] [numeric](18, 0) NOT NULL ,
>>[VendorIDD] [numeric](18, 0) NOT NULL ,
>>[InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS NOT NULL ,
>>[InvoiceDate] [datetime] NOT NULL ,
>>[TotImponibile] [float] NOT NULL ,
>>[TotIva] [float] NOT NULL ,
>>[TotInvoice] [float] NOT NULL ,
>>[TotImponibileF] [float] NOT NULL ,
>>[TotIvaF] [float] NOT NULL ,
>>[TotInvoiceF] [float] NOT NULL ,
>>[CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>>[InvoiceToCheck] [float] NOT NULL ,
>>[VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>>[VendorType] [numeric](18, 0) NOT NULL ,
>>[TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
>>[Checked] [bit] NOT NULL ,
>>[NotaCredito] [bit] NOT NULL ,
>>[AutoFattura] [bit] NOT NULL ,
>>[WhoDeleted] [numeric](18, 0) NOT NULL ,
>>[DataDeleted] [datetime] NOT NULL ,
>>[PaymentTermsID] [numeric](18, 0) NOT NULL
>>/**
>>from program is
>>"execute ODM1 iID "
>>iID is the numeric for the record ID and goes by adoQuery
>>Thanks,
>>Paolol
>>

help out of control query

Hi,
I jsut had a big problem, a table of 15000 was updated on 10000 for a
bit changed to true and all the record show the same datetime for the
change, the only query how can do this change is this :
/**
CREATE PROCEDURE OdM1
@.InvoicesPassID [numeric]
AS
update InvoicesPassive
set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
where ID=@.InvoicesPassID
/**
How this query can do that ?
Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
Thanks for any suggestion.
PaololOnly the affected rows should reflect the new datetime.
jens Suessmeyer.|||Hi
Can you show us a table structure and how do you assign a parameter to the
SP?
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I jsut had a big problem, a table of 15000 was updated on 10000 for a bit
> changed to true and all the record show the same datetime for the change,
> the only query how can do this change is this :
> /**
> CREATE PROCEDURE OdM1
> @.InvoicesPassID [numeric]
> AS
> update InvoicesPassive
> set Deleted=1 , WhoDeleted=@.UserID , DataDeleted=getdate()
> where ID=@.InvoicesPassID
> /**
> How this query can do that ?
> Can a numeric have a jolly number ? and work as a LIKE 'x%' ?
> Thanks for any suggestion.
> Paolol|||Uri Dimant ha scritto:
> Hi
> Can you show us a table structure and how do you assign a parameter to th
e
> SP?
>
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:utzQjbVAGHA.1676@.TK2MSFTNGP09.phx.gbl...
>
>
>
Hi NP
/** TABLE
[ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[SitesID] [numeric](18, 0) NOT NULL ,
[CompanyID] [numeric](18, 0) NOT NULL ,
[Via] [numeric](18, 0) NOT NULL ,
[Deleted] [bit] NOT NULL ,
[Void] [bit] NOT NULL ,
[CheckSigla] [bit] NOT NULL ,
[UserIDIN] [numeric](18, 0) NOT NULL ,
[UserIDMOD] [numeric](18, 0) NOT NULL ,
[DataIN] [datetime] NOT NULL ,
[DataMod] [datetime] NOT NULL ,
[VendorID] [numeric](18, 0) NOT NULL ,
[VendorIDD] [numeric](18, 0) NOT NULL ,
[InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS N
OT
NULL ,
[InvoiceDate] [datetime] NOT NULL ,
[TotImponibile] [float] NOT NULL ,
[TotIva] [float] NOT NULL ,
[TotInvoice] [float] NOT NULL ,
[TotImponibileF] [float] NOT NULL ,
[TotIvaF] [float] NOT NULL ,
[TotInvoiceF] [float] NOT NULL ,
[CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[InvoiceToCheck] [float] NOT NULL ,
[VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NO
T
NULL ,
[VendorType] [numeric](18, 0) NOT NULL ,
[TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NU
LL ,
[Checked] [bit] NOT NULL ,
[NotaCredito] [bit] NOT NULL ,
[AutoFattura] [bit] NOT NULL ,
[WhoDeleted] [numeric](18, 0) NOT NULL ,
[DataDeleted] [datetime] NOT NULL ,
[PaymentTermsID] [numeric](18, 0) NOT NULL
/**
from program is
"execute ODM1 iID "
iID is the numeric for the record ID and goes by adoQuery
Thanks,
Paolol|||Hi
Well ,looks strange.Do you have any triggers defined on the table?
create table #test
(
col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
col2 char(1)
)
insert into #test (col2) values ('a')
insert into #test (col2)values ('b')
insert into #test (col2) values ('c')
select * from #test
declare @.p numeric
set @.p=1
update #test set col2 ='g' where col1=@.p.
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
> Uri Dimant ha scritto:
> Hi NP
> /** TABLE
> [ID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> [SitesID] [numeric](18, 0) NOT NULL ,
> [CompanyID] [numeric](18, 0) NOT NULL ,
> [Via] [numeric](18, 0) NOT NULL ,
> [Deleted] [bit] NOT NULL ,
> [Void] [bit] NOT NULL ,
> [CheckSigla] [bit] NOT NULL ,
> [UserIDIN] [numeric](18, 0) NOT NULL ,
> [UserIDMOD] [numeric](18, 0) NOT NULL ,
> [DataIN] [datetime] NOT NULL ,
> [DataMod] [datetime] NOT NULL ,
> [VendorID] [numeric](18, 0) NOT NULL ,
> [VendorIDD] [numeric](18, 0) NOT NULL ,
> [InvoiceNumber] [varchar] (50) COLLATE QL_Latin1_General_CP1_CI_AS
NOT
> NULL ,
> [InvoiceDate] [datetime] NOT NULL ,
> [TotImponibile] [float] NOT NULL ,
> [TotIva] [float] NOT NULL ,
> [TotInvoice] [float] NOT NULL ,
> [TotImponibileF] [float] NOT NULL ,
> [TotIvaF] [float] NOT NULL ,
> [TotInvoiceF] [float] NOT NULL ,
> [CurrInvoice] [varchar] (3) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT NULL
> ,
> [InvoiceToCheck] [float] NOT NULL ,
> [VendorName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT NULL
> ,
> [VendorType] [numeric](18, 0) NOT NULL ,
> [TaxCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
> [Checked] [bit] NOT NULL ,
> [NotaCredito] [bit] NOT NULL ,
> [AutoFattura] [bit] NOT NULL ,
> [WhoDeleted] [numeric](18, 0) NOT NULL ,
> [DataDeleted] [datetime] NOT NULL ,
> [PaymentTermsID] [numeric](18, 0) NOT NULL
> /**
> from program is
> "execute ODM1 iID "
> iID is the numeric for the record ID and goes by adoQuery
> Thanks,
> Paolol|||Hi Uri,
yes very strange
No no trigger at all, and this procedure is not called by any other, is
a stand alone procedure and the most strange think is the DataDeleted
that is exactly the same for all deleted record !!! up to the millisecond !!
Uri Dimant ha scritto:
> Hi
> Well ,looks strange.Do you have any triggers defined on the table?
>
> create table #test
> (
> col1 [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
> col2 char(1)
> )
> insert into #test (col2) values ('a')
> insert into #test (col2)values ('b')
> insert into #test (col2) values ('c')
> select * from #test
> declare @.p numeric
> set @.p=1
> update #test set col2 ='g' where col1=@.p.
>
> "paolol" <paolol@._nospamma_salsan.net> wrote in message
> news:Ou%23CxJWAGHA.2156@.TK2MSFTNGP11.phx.gbl...
>
>
>|||My guess is that someone executed some other UPDATE or stored procedure to p
erform this action...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"paolol" <paolol@._nospamma_salsan.net> wrote in message
news:%23b1zOXWAGHA.3064@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
> Hi Uri,
> yes very strange
> No no trigger at all, and this procedure is not called by any other, is a
stand alone procedure
> and the most strange think is the DataDeleted that is exactly the same for
all deleted record !!!
> up to the millisecond !!
>
> Uri Dimant ha scritto:

Help ordering IN clause using passed order

I am trying to make the IN clause of a stored procedure return the rows in
the order in which the IN clause values were specified. What I have is a
table that can be sorted on a number of columns yet I want to pull back a
subset of rows. I have the set of rows needed but I am unable to return the
rows in the correct order using the IN clause.
For example:
SELECT
T.ID,
T.Name
FROM
MyTable
WHERE
T.ID IN ('1,3,2')
Notice that the ID order is 1,3,2. I want the rows in that order without
having to use an Order By on the correct column. That would require that I
a) use dynamic SQL just to use the correct order by column or b) provide the
same query a bunch of times just changing the sorting. I would prefer to not
do either.
Is this possible in SQL Server?One option is to use a CASE expression like:
ORDER BY CASE id WHEN 1 THEN 1
WHEN 3 THEN 2
WHEN 2 THEN 3
END ;
For a general option, use CHARINDEX or PATINDEX function like:
ORDER BY CHARINDEX( ',' + @.list + ',', ',' + id + ',' ) ;
Anith|||Tim Menninger wrote:
> I am trying to make the IN clause of a stored procedure return the rows in
> the order in which the IN clause values were specified. What I have is a
> table that can be sorted on a number of columns yet I want to pull back a
> subset of rows. I have the set of rows needed but I am unable to return th
e
> rows in the correct order using the IN clause.
> For example:
> SELECT
> T.ID,
> T.Name
> FROM
> MyTable
> WHERE
> T.ID IN ('1,3,2')
> Notice that the ID order is 1,3,2. I want the rows in that order without
> having to use an Order By on the correct column. That would require that I
> a) use dynamic SQL just to use the correct order by column or b) provide t
he
> same query a bunch of times just changing the sorting. I would prefer to n
ot
> do either.
> Is this possible in SQL Server?
You should know that you cannot reliably order any query without using
ORDER BY. Try:
DECLARE @.in VARCHAR(100)
SET @.in = '1,3,2'
SELECT T.id, T.name
FROM MyTable
WHERE CHARINDEX(','+CAST(id AS VARCHAR)+',',','+@.in+',')>0
ORDER BY CHARINDEX(','+CAST(id AS VARCHAR)+',',','+@.in+',');
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||I'd try to modify Erland Sommarskog's UDF iter_charlist_to_table that
parses a comma-separated string, found at
http://www.sommarskog.se/arrays-in-sql.html
CREATE FUNCTION iter_charlist_to_int_table
(@.list ntext,
@.delimiter nchar(1) = N',')
RETURNS @.tbl TABLE (listpos int IDENTITY(1, 1) NOT NULL,
value int,
nstr nvarchar(2000)) AS
BEGIN
DECLARE @.pos int,
@.textpos int,
@.chunklen smallint,
@.tmpstr nvarchar(4000),
@.leftover nvarchar(4000),
@.tmpval nvarchar(4000)
SET @.textpos = 1
SET @.leftover = ''
WHILE @.textpos <= datalength(@.list) / 2
BEGIN
SET @.chunklen = 4000 - datalength(@.leftover) / 2
SET @.tmpstr = @.leftover + substring(@.list, @.textpos,
@.chunklen)
SET @.textpos = @.textpos + @.chunklen
SET @.pos = charindex(@.delimiter, @.tmpstr)
WHILE @.pos > 0
BEGIN
SET @.tmpval = ltrim(rtrim(left(@.tmpstr, @.pos - 1)))
INSERT @.tbl (value, nstr) VALUES(cast(@.tmpval as int),
@.tmpval)
SET @.tmpstr = substring(@.tmpstr, @.pos + 1, len(@.tmpstr))
SET @.pos = charindex(@.delimiter, @.tmpstr)
END
SET @.leftover = @.tmpstr
END
INSERT @.tbl(value, nstr) VALUES (cast(ltrim(rtrim(@.leftover)) as
int), ltrim(rtrim(@.leftover)))
RETURN
END
create table #t(i int)
insert into #t values(1)
insert into #t values(2)
insert into #t values(3)
insert into #t values(4)
insert into #t values(5)
select #t.i from #t, dbo.iter_charlist_to_int_table('1,3,2', ',') t
where #t.i=t.value
order by t.listpos
i
--
1
3
2
(3 row(s) affected)|||Your IN clause has only one member. You are confusing IN (1,3,2) and IN
('1,3,2'). You probably need to use dynamic SQL anyway to get your query
working the way you want it.
For example, with this:
create table fred
(
ID varchar(2),
Name varchar(100)
)
go
insert into fred(ID,Name)
select '1','Jim' union
select '2','Tom' union
select '3','Appleby'
select id,name from fred where id in ('1,2')
The select doesn't return anything. If ID were an int, you would get a
syntax error in the select statement
"Tim Menninger" <tmenninger@.comcast.net> wrote in message
news:e77bacLMGHA.1124@.TK2MSFTNGP10.phx.gbl...
>I am trying to make the IN clause of a stored procedure return the rows in
>the order in which the IN clause values were specified. What I have is a
>table that can be sorted on a number of columns yet I want to pull back a
>subset of rows. I have the set of rows needed but I am unable to return the
>rows in the correct order using the IN clause.
> For example:
> SELECT
> T.ID,
> T.Name
> FROM
> MyTable
> WHERE
> T.ID IN ('1,3,2')
> Notice that the ID order is 1,3,2. I want the rows in that order without
> having to use an Order By on the correct column. That would require that I
> a) use dynamic SQL just to use the correct order by column or b) provide
> the same query a bunch of times just changing the sorting. I would prefer
> to not do either.
> Is this possible in SQL Server?
>|||Someone was asleep in RDBMS 101 class! What is the definition of a
table? It models a set of rows. By definition a set has no ordering.
This is what you should have learned the first w in class.
Do this in the front end, where all formatting and presentation is done
in a tiered architecture (w #2) or with an ORDER BY clause to
convert from a tale to a cursor.sql

Help optmizing a stored proc

I have this

CREATE PROCEDURE dbo.cmsGetTaskOrdersAndFunding2
(
@.FundingDate SMALLDATETIME,
@.BillingContractID INT, -- null for all contracts
@.Filter BIT = NULL

)
AS
-- get list of taskorders with their respective fundingtotals as of
specified date
IF @.Filter IS NULL
BEGIN
SELECT TO1.TaskOrderID
FROM TaskOrder TO1
LEFT OUTER JOIN
WHERE (@.BillingContractID IS NULL OR TO1.BillingContractID =
@.BillingContractID)
END
ELSE
BEGIN
SELECT TO1.TaskOrderID,
FROM TaskOrder TO1
WHERE (@.BillingContractID IS NULL OR TO1.BillingContractID =
@.BillingContractID) AND TO1.Retired <> @.Filter
END

RETURN
GO
------
Is there a less redundant way to write this? basically @.Filter is an
optional parameter, if it isn't present, I want to return all records and if
it is present all records where Retired <> @.Filter. Any ideas? Can I wrap
the WHERE clause in an if statement? Or is there a better way?

TIA,
ChrisJust one block:

-- get list of taskorders with their respective fundingtotals as of
specified date
SELECT TO1.TaskOrderID,
FROM TaskOrder TO1
WHERE (@.BillingContractID IS NULL OR TO1.BillingContractID =
@.BillingContractID)
AND (@.Filter IS NULL OR TO1.Retired <> @.Filter)

Note this last line. If @.Filter is NULL, the entire block is ALWAYS
true so "TO1.Retired <> @.Filter" doesn't matter. If @.filter is not
null, "TO1.Retired <> @.Filter" is the part that matters.|||Sweet! Thanks man.

"figital" <mharen@.gmail.com> wrote in message
news:1141927222.299970.274010@.i39g2000cwa.googlegr oups.com...
> Just one block:
> -- get list of taskorders with their respective fundingtotals as of
> specified date
> SELECT TO1.TaskOrderID,
> FROM TaskOrder TO1
> WHERE (@.BillingContractID IS NULL OR TO1.BillingContractID =
> @.BillingContractID)
> AND (@.Filter IS NULL OR TO1.Retired <> @.Filter)
> Note this last line. If @.Filter is NULL, the entire block is ALWAYS
> true so "TO1.Retired <> @.Filter" doesn't matter. If @.filter is not
> null, "TO1.Retired <> @.Filter" is the part that matters.

Help optimizing query for large data set

Hi all... I'm hoping someone can help me with optimizing a query that is
taking a really long time because the data set is so large... Basically I
have a large table and I need to select on some date ranges.
Will adding an index for a datetime column help performance for queries of
the form (dtCol >= DATE1) and (dtCol < DATE2)?
-mdbOn Fri, 13 Jul 2007 14:11:21 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:

>Hi all... I'm hoping someone can help me with optimizing a query that is
>taking a really long time because the data set is so large... Basically I
>have a large table and I need to select on some date ranges.
>Will adding an index for a datetime column help performance for queries of
>the form (dtCol >= DATE1) and (dtCol < DATE2)?
>-mdb
The answer is the most common one here: It depends.
If the index were clustered on the date then it certainly will help.
But I would not rush to cluster on the date, the choice of a proper
clustered index is not that simple.
If the date ranges are very narrow compared to the overall table then
a non-clustered index on the date may very well be chosen by the
optimizer and save time. The optimizer is going to estimate the
number of pages it will have to read in random order to use the index,
and compare that to the number of pages it will have to read to scan
the entire table. The smaller number wins.
Without more information on the table, data and query I don't know
what else to say.
Roy Harvey
Beacon Falls, CT|||Roy Harvey <roy_harvey@.snet.net> wrote in
news:k4uf935qq5jqltamrffo96mgsemsnojorh@.
4ax.com:

> If the index were clustered on the date then it certainly will help.
> But I would not rush to cluster on the date, the choice of a proper
> clustered index is not that simple.
> If the date ranges are very narrow compared to the overall table then
> a non-clustered index on the date may very well be chosen by the
> optimizer and save time. The optimizer is going to estimate the
> number of pages it will have to read in random order to use the index,
> and compare that to the number of pages it will have to read to scan
> the entire table. The smaller number wins.
> Without more information on the table, data and query I don't know
> what else to say.
>
Well I can tell you that the dates are very evenly spread out. Each row is
an entry from about 200 different clients where each event from a client is
separated by about 3-4 minutes, with very little variation. There is an
index on another column (an integer) and the query is selecting values from
that table where the int value equals a value and the date column is
between a range, and is inner joining that to 3 other tables through a
fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
what you said?
It sounds as if a clustered index would help in this case. Do you agree?
-mdb|||I really can't tell from the information available.
If you post the table definitions, including keys and indexes, as well
as sizes and the query that is performing poorly someone might be able
to give meaningful advice.
Roy Harvey
Beacon Falls, CT
On Mon, 16 Jul 2007 06:35:38 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:

>Roy Harvey <roy_harvey@.snet.net> wrote in
> news:k4uf935qq5jqltamrffo96mgsemsnojorh@.
4ax.com:
>
>Well I can tell you that the dates are very evenly spread out. Each row is
>an entry from about 200 different clients where each event from a client is
>separated by about 3-4 minutes, with very little variation. There is an
>index on another column (an integer) and the query is selecting values from
>that table where the int value equals a value and the date column is
>between a range, and is inner joining that to 3 other tables through a
>fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
>what you said?
>It sounds as if a clustered index would help in this case. Do you agree?
>-mdb

Help optimizing query for large data set

Hi all... I'm hoping someone can help me with optimizing a query that is
taking a really long time because the data set is so large... Basically I
have a large table and I need to select on some date ranges.
Will adding an index for a datetime column help performance for queries of
the form (dtCol >= DATE1) and (dtCol < DATE2)?
-mdbOn Fri, 13 Jul 2007 14:11:21 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:
>Hi all... I'm hoping someone can help me with optimizing a query that is
>taking a really long time because the data set is so large... Basically I
>have a large table and I need to select on some date ranges.
>Will adding an index for a datetime column help performance for queries of
>the form (dtCol >= DATE1) and (dtCol < DATE2)?
>-mdb
The answer is the most common one here: It depends.
If the index were clustered on the date then it certainly will help.
But I would not rush to cluster on the date, the choice of a proper
clustered index is not that simple.
If the date ranges are very narrow compared to the overall table then
a non-clustered index on the date may very well be chosen by the
optimizer and save time. The optimizer is going to estimate the
number of pages it will have to read in random order to use the index,
and compare that to the number of pages it will have to read to scan
the entire table. The smaller number wins.
Without more information on the table, data and query I don't know
what else to say.
Roy Harvey
Beacon Falls, CT|||Roy Harvey <roy_harvey@.snet.net> wrote in
news:k4uf935qq5jqltamrffo96mgsemsnojorh@.4ax.com:
> If the index were clustered on the date then it certainly will help.
> But I would not rush to cluster on the date, the choice of a proper
> clustered index is not that simple.
> If the date ranges are very narrow compared to the overall table then
> a non-clustered index on the date may very well be chosen by the
> optimizer and save time. The optimizer is going to estimate the
> number of pages it will have to read in random order to use the index,
> and compare that to the number of pages it will have to read to scan
> the entire table. The smaller number wins.
> Without more information on the table, data and query I don't know
> what else to say.
>
Well I can tell you that the dates are very evenly spread out. Each row is
an entry from about 200 different clients where each event from a client is
separated by about 3-4 minutes, with very little variation. There is an
index on another column (an integer) and the query is selecting values from
that table where the int value equals a value and the date column is
between a range, and is inner joining that to 3 other tables through a
fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
what you said?
It sounds as if a clustered index would help in this case. Do you agree?
-mdb|||I really can't tell from the information available.
If you post the table definitions, including keys and indexes, as well
as sizes and the query that is performing poorly someone might be able
to give meaningful advice.
Roy Harvey
Beacon Falls, CT
On Mon, 16 Jul 2007 06:35:38 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:
>Roy Harvey <roy_harvey@.snet.net> wrote in
>news:k4uf935qq5jqltamrffo96mgsemsnojorh@.4ax.com:
>> If the index were clustered on the date then it certainly will help.
>> But I would not rush to cluster on the date, the choice of a proper
>> clustered index is not that simple.
>> If the date ranges are very narrow compared to the overall table then
>> a non-clustered index on the date may very well be chosen by the
>> optimizer and save time. The optimizer is going to estimate the
>> number of pages it will have to read in random order to use the index,
>> and compare that to the number of pages it will have to read to scan
>> the entire table. The smaller number wins.
>> Without more information on the table, data and query I don't know
>> what else to say.
>Well I can tell you that the dates are very evenly spread out. Each row is
>an entry from about 200 different clients where each event from a client is
>separated by about 3-4 minutes, with very little variation. There is an
>index on another column (an integer) and the query is selecting values from
>that table where the int value equals a value and the date column is
>between a range, and is inner joining that to 3 other tables through a
>fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
>what you said?
>It sounds as if a clustered index would help in this case. Do you agree?
>-mdb

Help optimizing query for large data set

Hi all... I'm hoping someone can help me with optimizing a query that is
taking a really long time because the data set is so large... Basically I
have a large table and I need to select on some date ranges.
Will adding an index for a datetime column help performance for queries of
the form (dtCol >= DATE1) and (dtCol < DATE2)?
-mdb
On Fri, 13 Jul 2007 14:11:21 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:

>Hi all... I'm hoping someone can help me with optimizing a query that is
>taking a really long time because the data set is so large... Basically I
>have a large table and I need to select on some date ranges.
>Will adding an index for a datetime column help performance for queries of
>the form (dtCol >= DATE1) and (dtCol < DATE2)?
>-mdb
The answer is the most common one here: It depends.
If the index were clustered on the date then it certainly will help.
But I would not rush to cluster on the date, the choice of a proper
clustered index is not that simple.
If the date ranges are very narrow compared to the overall table then
a non-clustered index on the date may very well be chosen by the
optimizer and save time. The optimizer is going to estimate the
number of pages it will have to read in random order to use the index,
and compare that to the number of pages it will have to read to scan
the entire table. The smaller number wins.
Without more information on the table, data and query I don't know
what else to say.
Roy Harvey
Beacon Falls, CT
|||Roy Harvey <roy_harvey@.snet.net> wrote in
news:k4uf935qq5jqltamrffo96mgsemsnojorh@.4ax.com:

> If the index were clustered on the date then it certainly will help.
> But I would not rush to cluster on the date, the choice of a proper
> clustered index is not that simple.
> If the date ranges are very narrow compared to the overall table then
> a non-clustered index on the date may very well be chosen by the
> optimizer and save time. The optimizer is going to estimate the
> number of pages it will have to read in random order to use the index,
> and compare that to the number of pages it will have to read to scan
> the entire table. The smaller number wins.
> Without more information on the table, data and query I don't know
> what else to say.
>
Well I can tell you that the dates are very evenly spread out. Each row is
an entry from about 200 different clients where each event from a client is
separated by about 3-4 minutes, with very little variation. There is an
index on another column (an integer) and the query is selecting values from
that table where the int value equals a value and the date column is
between a range, and is inner joining that to 3 other tables through a
fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
what you said?
It sounds as if a clustered index would help in this case. Do you agree?
-mdb
|||I really can't tell from the information available.
If you post the table definitions, including keys and indexes, as well
as sizes and the query that is performing poorly someone might be able
to give meaningful advice.
Roy Harvey
Beacon Falls, CT
On Mon, 16 Jul 2007 06:35:38 -0700, Michael Bray
<mbrayATctiusaDOTcom@.you.figure.it.out.com> wrote:

>Roy Harvey <roy_harvey@.snet.net> wrote in
>news:k4uf935qq5jqltamrffo96mgsemsnojorh@.4ax.com :
>
>Well I can tell you that the dates are very evenly spread out. Each row is
>an entry from about 200 different clients where each event from a client is
>separated by about 3-4 minutes, with very little variation. There is an
>index on another column (an integer) and the query is selecting values from
>that table where the int value equals a value and the date column is
>between a range, and is inner joining that to 3 other tables through a
>fourth common table (i.e. A-Z-B, A-Z-C, A-Z-D). Does that alter any of
>what you said?
>It sounds as if a clustered index would help in this case. Do you agree?
>-mdb

help optimizing query

I have a query that is taking about 12 minutes to run. I'm sure there has to be a way to speed it up...i'm just not sure how. any suggestions on how to rewrite this would be much appreciated. i think it has something to do with the "not in" join.

Select
Distinct T.TSNUMB
from
TSR T
where
T.TSSTAT='C'
and T.TSCDAT >= '01-Oct-03'
and T.TSCDAT <= sysdate
and T.TSORGA in (Select distinct O.ORORGA
from OrgCode O
where
O.ORTCON like '123456%'
and T.TSNUMB not in (select distinct w.wcnumb
from
wobaskdtl w
where w.wcbask like '%-V'))You could try using NOT EXISTS instead of NOT IN:

Select
Distinct T.TSNUMB
from
TSR T
where
T.TSSTAT='C'
and T.TSCDAT >= '01-Oct-03'
and T.TSCDAT <= sysdate
and T.TSORGA in (Select distinct O.ORORGA
from OrgCode O
where
O.ORTCON like '123456%'
and not exists (select null
from
wobaskdtl w
where w.wcbask like '%-V' and w.wcnumb = t.tsnumb))

Also make sure your tables have been analyzed and the statistics are not stale (I'm inferring this is Oracle?)|||thank you...not sure i completely understand what is going on there (have to sit down and really look at it) but it works.sql

Help Optimize my Query

that takes 20 seconds may however maximally 5 last
how am I to provide the indices? fill factor?
SELECT TOP 250 dbo.IHLEAktionenPlan.AktionenPlanID,
dbo.IHLEAktionenPlan.AdressID, dbo.IHLEMassnahmeStamm.Bezeichnung AS
Massnahme,
dbo.IHLEAktionenStamm.Name AS Aktion,
dbo.IHLEAdressenStamm.Name1 AS KundenName,
dbo.IHLEAktionenPlan.GeplanteAusfuehrung,
dbo.IHLEAktionenPlan.GueltigBis,
dbo.IHLEAktionenPlan.Wiedervorlage, dbo.IHLEAktionenPlan.WiedervorlageText,
dbo.IHLEAktionenPlan.NachbearbeitungsCodeID,
dbo.IHLEMassnahmePlan.Statuspruefung AS StatusPruefung,
dbo.IHLEMarketingParameter.StatusKennzeichen AS
StatusKennzeichen, dbo.IHLEMarketingParameter.Leistungsangebote AS
LeistungsAngebote,
dbo.IHLEMassnahmePlan.LeistungsAngebotPruefung AS
LeistungsAngebotPruefung,
dbo.IHLEMarketingParameter.Kommunikationsart AS
KommunikationsArt,
dbo.IHLEMassnahmePlan.KommunikationsArtPruefung AS
KommunikationsArtPruefung
FROM dbo.IHLEAktionenPlan INNER JOIN
dbo.IHLEMassnahmeStamm ON
dbo.IHLEAktionenPlan.MassnahmeID = dbo.IHLEMassnahmeStamm.MassnahmeID INNER
JOIN
dbo.IHLEAktionenStamm ON dbo.IHLEAktionenPlan.AktionID
= dbo.IHLEAktionenStamm.AktionID INNER JOIN
dbo.IHLEMassnahmePlan ON
dbo.IHLEAktionenPlan.MassnahmePlanID = dbo.IHLEMassnahmePlan.MassnahmePlanID
INNER JOIN
dbo.IHLEAdressenStamm ON dbo.IHLEAktionenPlan.AdressID
= dbo.IHLEAdressenStamm.AdressID INNER JOIN
dbo.IHLEMarketingParameter ON
dbo.IHLEAktionenPlan.AdressID = dbo.IHLEMarketingParameter.AdressID
WHERE (dbo.IHLEAktionenPlan.AusgefuehrtAm IS NOT NULL) AND
(dbo.IHLEMassnahmeStamm.LandID = @.LANDID) AND
(dbo.IHLEAktionenPlan.AusgefuehrtAm >= @.DATEFROM) AND
(dbo.IHLEAktionenPlan.AusgefuehrtAm <= @.DATETO)
ORDER BY dbo.IHLEAktionenPlan.Wiedervorlage,
dbo.IHLEAktionenPlan.GeplanteAusfuehrungHi
Have you looked at an execution plan? Does an optimizer available to use
indexes defined on the tables?
"mPiccoli" <mPiccoli@.discussions.microsoft.com> wrote in message
news:FA9C59EB-0FD4-4850-9A6D-51F848BEDE8F@.microsoft.com...
> that takes 20 seconds may however maximally 5 last
> how am I to provide the indices? fill factor?
> SELECT TOP 250 dbo.IHLEAktionenPlan.AktionenPlanID,
> dbo.IHLEAktionenPlan.AdressID, dbo.IHLEMassnahmeStamm.Bezeichnung AS
> Massnahme,
> dbo.IHLEAktionenStamm.Name AS Aktion,
> dbo.IHLEAdressenStamm.Name1 AS KundenName,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung,
> dbo.IHLEAktionenPlan.GueltigBis,
> dbo.IHLEAktionenPlan.Wiedervorlage,
dbo.IHLEAktionenPlan.WiedervorlageText,
> dbo.IHLEAktionenPlan.NachbearbeitungsCodeID,
> dbo.IHLEMassnahmePlan.Statuspruefung AS StatusPruefung,
> dbo.IHLEMarketingParameter.StatusKennzeichen AS
> StatusKennzeichen, dbo.IHLEMarketingParameter.Leistungsangebote AS
> LeistungsAngebote,
> dbo.IHLEMassnahmePlan.LeistungsAngebotPruefung AS
> LeistungsAngebotPruefung,
> dbo.IHLEMarketingParameter.Kommunikationsart AS
> KommunikationsArt,
> dbo.IHLEMassnahmePlan.KommunikationsArtPruefung AS
> KommunikationsArtPruefung
> FROM dbo.IHLEAktionenPlan INNER JOIN
> dbo.IHLEMassnahmeStamm ON
> dbo.IHLEAktionenPlan.MassnahmeID = dbo.IHLEMassnahmeStamm.MassnahmeID
INNER
> JOIN
> dbo.IHLEAktionenStamm ON
dbo.IHLEAktionenPlan.AktionID
> = dbo.IHLEAktionenStamm.AktionID INNER JOIN
> dbo.IHLEMassnahmePlan ON
> dbo.IHLEAktionenPlan.MassnahmePlanID =
dbo.IHLEMassnahmePlan.MassnahmePlanID
> INNER JOIN
> dbo.IHLEAdressenStamm ON
dbo.IHLEAktionenPlan.AdressID
> = dbo.IHLEAdressenStamm.AdressID INNER JOIN
> dbo.IHLEMarketingParameter ON
> dbo.IHLEAktionenPlan.AdressID = dbo.IHLEMarketingParameter.AdressID
> WHERE (dbo.IHLEAktionenPlan.AusgefuehrtAm IS NOT NULL) AND
> (dbo.IHLEMassnahmeStamm.LandID = @.LANDID) AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm >= @.DATEFROM)
AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm <= @.DATETO)
> ORDER BY dbo.IHLEAktionenPlan.Wiedervorlage,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung|||Did you look at the joined and the condition columns, are they indexed ?
Thats would be the main improment.
Jens SUessmeyer.
"mPiccoli" <mPiccoli@.discussions.microsoft.com> schrieb im Newsbeitrag
news:FA9C59EB-0FD4-4850-9A6D-51F848BEDE8F@.microsoft.com...
> that takes 20 seconds may however maximally 5 last
> how am I to provide the indices? fill factor?
> SELECT TOP 250 dbo.IHLEAktionenPlan.AktionenPlanID,
> dbo.IHLEAktionenPlan.AdressID, dbo.IHLEMassnahmeStamm.Bezeichnung AS
> Massnahme,
> dbo.IHLEAktionenStamm.Name AS Aktion,
> dbo.IHLEAdressenStamm.Name1 AS KundenName,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung,
> dbo.IHLEAktionenPlan.GueltigBis,
> dbo.IHLEAktionenPlan.Wiedervorlage,
> dbo.IHLEAktionenPlan.WiedervorlageText,
> dbo.IHLEAktionenPlan.NachbearbeitungsCodeID,
> dbo.IHLEMassnahmePlan.Statuspruefung AS StatusPruefung,
> dbo.IHLEMarketingParameter.StatusKennzeichen AS
> StatusKennzeichen, dbo.IHLEMarketingParameter.Leistungsangebote AS
> LeistungsAngebote,
> dbo.IHLEMassnahmePlan.LeistungsAngebotPruefung AS
> LeistungsAngebotPruefung,
> dbo.IHLEMarketingParameter.Kommunikationsart AS
> KommunikationsArt,
> dbo.IHLEMassnahmePlan.KommunikationsArtPruefung AS
> KommunikationsArtPruefung
> FROM dbo.IHLEAktionenPlan INNER JOIN
> dbo.IHLEMassnahmeStamm ON
> dbo.IHLEAktionenPlan.MassnahmeID = dbo.IHLEMassnahmeStamm.MassnahmeID
> INNER
> JOIN
> dbo.IHLEAktionenStamm ON
> dbo.IHLEAktionenPlan.AktionID
> = dbo.IHLEAktionenStamm.AktionID INNER JOIN
> dbo.IHLEMassnahmePlan ON
> dbo.IHLEAktionenPlan.MassnahmePlanID =
> dbo.IHLEMassnahmePlan.MassnahmePlanID
> INNER JOIN
> dbo.IHLEAdressenStamm ON
> dbo.IHLEAktionenPlan.AdressID
> = dbo.IHLEAdressenStamm.AdressID INNER JOIN
> dbo.IHLEMarketingParameter ON
> dbo.IHLEAktionenPlan.AdressID = dbo.IHLEMarketingParameter.AdressID
> WHERE (dbo.IHLEAktionenPlan.AusgefuehrtAm IS NOT NULL) AND
> (dbo.IHLEMassnahmeStamm.LandID = @.LANDID) AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm >= @.DATEFROM) AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm <= @.DATETO)
> ORDER BY dbo.IHLEAktionenPlan.Wiedervorlage,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung|||First of all, When you have a query this long, with table and column names a
s
long as this, use aliases as much as possible to improve readability.
Example: Your
"mPiccoli" wrote:

> that takes 20 seconds may however maximally 5 last
> how am I to provide the indices? fill factor?
> SELECT TOP 250 dbo.IHLEAktionenPlan.AktionenPlanID,
> dbo.IHLEAktionenPlan.AdressID, dbo.IHLEMassnahmeStamm.Bezeichnung AS
> Massnahme,
> dbo.IHLEAktionenStamm.Name AS Aktion,
> dbo.IHLEAdressenStamm.Name1 AS KundenName,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung,
> dbo.IHLEAktionenPlan.GueltigBis,
> dbo.IHLEAktionenPlan.Wiedervorlage, dbo.IHLEAktionenPlan.WiedervorlageText
,
> dbo.IHLEAktionenPlan.NachbearbeitungsCodeID,
> dbo.IHLEMassnahmePlan.Statuspruefung AS StatusPruefung,
> dbo.IHLEMarketingParameter.StatusKennzeichen AS
> StatusKennzeichen, dbo.IHLEMarketingParameter.Leistungsangebote AS
> LeistungsAngebote,
> dbo.IHLEMassnahmePlan.LeistungsAngebotPruefung AS
> LeistungsAngebotPruefung,
> dbo.IHLEMarketingParameter.Kommunikationsart AS
> KommunikationsArt,
> dbo.IHLEMassnahmePlan.KommunikationsArtPruefung AS
> KommunikationsArtPruefung
> FROM dbo.IHLEAktionenPlan INNER JOIN
> dbo.IHLEMassnahmeStamm ON
> dbo.IHLEAktionenPlan.MassnahmeID = dbo.IHLEMassnahmeStamm.MassnahmeID INNE
R
> JOIN
> dbo.IHLEAktionenStamm ON dbo.IHLEAktionenPlan.Aktion
ID
> = dbo.IHLEAktionenStamm.AktionID INNER JOIN
> dbo.IHLEMassnahmePlan ON
> dbo.IHLEAktionenPlan.MassnahmePlanID = dbo.IHLEMassnahmePlan.MassnahmePlan
ID
> INNER JOIN
> dbo.IHLEAdressenStamm ON dbo.IHLEAktionenPlan.Adress
ID
> = dbo.IHLEAdressenStamm.AdressID INNER JOIN
> dbo.IHLEMarketingParameter ON
> dbo.IHLEAktionenPlan.AdressID = dbo.IHLEMarketingParameter.AdressID
> WHERE (dbo.IHLEAktionenPlan.AusgefuehrtAm IS NOT NULL) AND
> (dbo.IHLEMassnahmeStamm.LandID = @.LANDID) AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm >= @.DATEFROM) AN
D
> (dbo.IHLEAktionenPlan.AusgefuehrtAm <= @.DATETO)
> ORDER BY dbo.IHLEAktionenPlan.Wiedervorlage,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung|||First of all, to suggest what indices should exist, it would be good to know
the structure of the tables involved, and the DRI (Declared Referential
Integrity) constraints on the tables... Post the DDL...
Next, When you have a query this long, with table and column names as
long as this, use aliases as much as possible, and indent the major clauses
of teh SQL, to improve readability.
for Example:
The following is identical to your query
SELECT TOP 250 Ap.AktionenPlanID,
Ap.AdressID, MS.Bezeichnung Massnahme,
Ak.Name Aktion, Ad.Name1 KundenName,
Ap.GeplanteAusfuehrung, Ap.GueltigBis,
Ap.Wiedervorlage, Ap.WiedervorlageText,
Ap.NachbearbeitungsCodeID,
Mp.Statuspruefung StatusPruefung,
Mk.StatusKennzeichen StatusKennzeichen,
Mk.Leistungsangebote LeistungsAngebote,
Mp.LeistungsAngebotPruefung LeistungsAngebotPruefung,
Mk.Kommunikationsart KommunikationsArt,
Mp.KommunikationsArtPruefung KommunikationsArtPruefung
FROM dbo.IHLEAktionenPlan Ap
JOIN dbo.IHLEMassnahmeStamm Ms
ON Ms.MassnahmeID = Ap.MassnahmeID
JOIN dbo.IHLEAktionenStamm Ak
ON Ak.AktionID = Ap.AktionID
JOIN dbo.IHLEAktionenStamm Mp
ON Mp.MassnahmePlanID = Ap.MassnahmePlanID
JOIN dbo.IHLEAdressenStamm Ad
ON Ad.AdressID = Ap.AdressID
JOIN dbo.IHLEMarketingParameter Mk
ON Mk.AdressID = Ap.AdressID =
WHERE Ap.AusgefuehrtAm IS NOT NULL
AND MS.LandID = @.LANDID
AND Ap.AusgefuehrtAm >= @.DATEFROM
AND Ap.AusgefuehrtAm <= @.DATETO
ORDER BY Ap.Wiedervorlage, Ap.GeplanteAusfuehrung
"mPiccoli" wrote:

> that takes 20 seconds may however maximally 5 last
> how am I to provide the indices? fill factor?
> SELECT TOP 250 dbo.IHLEAktionenPlan.AktionenPlanID,
> dbo.IHLEAktionenPlan.AdressID, dbo.IHLEMassnahmeStamm.Bezeichnung AS
> Massnahme,
> dbo.IHLEAktionenStamm.Name AS Aktion,
> dbo.IHLEAdressenStamm.Name1 AS KundenName,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung,
> dbo.IHLEAktionenPlan.GueltigBis,
> dbo.IHLEAktionenPlan.Wiedervorlage, dbo.IHLEAktionenPlan.WiedervorlageText
,
> dbo.IHLEAktionenPlan.NachbearbeitungsCodeID,
> dbo.IHLEMassnahmePlan.Statuspruefung AS StatusPruefung,
> dbo.IHLEMarketingParameter.StatusKennzeichen AS
> StatusKennzeichen, dbo.IHLEMarketingParameter.Leistungsangebote AS
> LeistungsAngebote,
> dbo.IHLEMassnahmePlan.LeistungsAngebotPruefung AS
> LeistungsAngebotPruefung,
> dbo.IHLEMarketingParameter.Kommunikationsart AS
> KommunikationsArt,
> dbo.IHLEMassnahmePlan.KommunikationsArtPruefung AS
> KommunikationsArtPruefung
> FROM dbo.IHLEAktionenPlan INNER JOIN
> dbo.IHLEMassnahmeStamm ON
> dbo.IHLEAktionenPlan.MassnahmeID = dbo.IHLEMassnahmeStamm.MassnahmeID INNE
R
> JOIN
> dbo.IHLEAktionenStamm ON dbo.IHLEAktionenPlan.Aktion
ID
> = dbo.IHLEAktionenStamm.AktionID INNER JOIN
> dbo.IHLEMassnahmePlan ON
> dbo.IHLEAktionenPlan.MassnahmePlanID = dbo.IHLEMassnahmePlan.MassnahmePlan
ID
> INNER JOIN
> dbo.IHLEAdressenStamm ON dbo.IHLEAktionenPlan.Adress
ID
> = dbo.IHLEAdressenStamm.AdressID INNER JOIN
> dbo.IHLEMarketingParameter ON
> dbo.IHLEAktionenPlan.AdressID = dbo.IHLEMarketingParameter.AdressID
> WHERE (dbo.IHLEAktionenPlan.AusgefuehrtAm IS NOT NULL) AND
> (dbo.IHLEMassnahmeStamm.LandID = @.LANDID) AND
> (dbo.IHLEAktionenPlan.AusgefuehrtAm >= @.DATEFROM) AN
D
> (dbo.IHLEAktionenPlan.AusgefuehrtAm <= @.DATETO)
> ORDER BY dbo.IHLEAktionenPlan.Wiedervorlage,
> dbo.IHLEAktionenPlan.GeplanteAusfuehrung|||my indices:
PK – AktionenPlanID
IX – AdressID
IX1 – MassnahmeID,AktionID
IX2 – LandID,AusgefuehrtAm
IX3 – Wiedervorlage, GeplanteAusfuerhung
the table contains 1.500.000 data records
if I order by cluse do not use then takes only 4 seconds
can someone explain to me why?
"Jens Sü?meyer" wrote:

> Did you look at the joined and the condition columns, are they indexed ?
> Thats would be the main improment.
> Jens SUessmeyer.
>
> "mPiccoli" <mPiccoli@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:FA9C59EB-0FD4-4850-9A6D-51F848BEDE8F@.microsoft.com...
>
>|||my indices:
PK – AktionenPlanID
IX – AdressID
IX1 – MassnahmeID,AktionID
IX2 – LandID,AusgefuehrtAm
IX3 – Wiedervorlage, GeplanteAusfuerhung
the table contains 1.500.000 data records
if I order by cluse do not use then takes only 4 seconds
can someone explain to me why?
"Jens Sü?meyer" wrote:

> Did you look at the joined and the condition columns, are they indexed ?
> Thats would be the main improment.
> Jens SUessmeyer.
>
> "mPiccoli" <mPiccoli@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:FA9C59EB-0FD4-4850-9A6D-51F848BEDE8F@.microsoft.com...
>
>|||my indices:
PK – AktionenPlanID
IX – AdressID
IX1 – MassnahmeID,AktionID
IX2 – LandID,AusgefuehrtAm
IX3 – Wiedervorlage, GeplanteAusfuerhung
the table contains 1.500.000 data records
if I order by cluse do not use then takes only 4 seconds
can someone explain to me why?
"Uri Dimant" wrote:

> Hi
> Have you looked at an execution plan? Does an optimizer available to use
> indexes defined on the tables?
> "mPiccoli" <mPiccoli@.discussions.microsoft.com> wrote in message
> news:FA9C59EB-0FD4-4850-9A6D-51F848BEDE8F@.microsoft.com...
> dbo.IHLEAktionenPlan.WiedervorlageText,
> INNER
> dbo.IHLEAktionenPlan.AktionID
> dbo.IHLEMassnahmePlan.MassnahmePlanID
> dbo.IHLEAktionenPlan.AdressID
> AND
>
>|||my indices:
PK – AktionenPlanID
IX – AdressID
IX1 – MassnahmeID,AktionID
IX2 – LandID,AusgefuehrtAm
IX3 – Wiedervorlage, GeplanteAusfuerhung
the table contains 1.500.000 data records
if I order by cluse do not use then takes only 4 seconds
can someone explain to me why?|||On Tue, 26 Apr 2005 05:36:03 -0700, mPiccoli wrote:

>my indices:
>PK AktionenPlanID
>IX AdressID
>IX1 MassnahmeID,AktionID
>IX2 LandID,AusgefuehrtAm
>IX3 Wiedervorlage, GeplanteAusfuerhung
>the table contains 1.500.000 data records
>if I order by cluse do not use then takes only 4 seconds
>can someone explain to me why?
Hi mPiccoli,
If you leave out the ORDER BY, then SQL Server can return the rows in any
way it sees fit. With the ORDER BY, it has to do extra work.
If you comare execution plans, I guess you'll see one of the following
scenarios:
1. With ORDER BY, the index IX3 is used; without ORDER BY a different
index is used. Apparently, the other index can find the rows you need more
quickly; to satisfy the ORDER BY, the optimizer decides to use the index
that is already in the required order, even if it means that the rest of
the query takes some more work.
2. With ORDER BY, an extra sorting step is added, but the execution plan
doesn't change otherwise. Apparently, the optimizer estimates that getting
the rows in the wrong order first, then reordering them is better than
using a more expensive method to retrieve the rows.
Since I know nothing about your table structure or data, and the query
itself is quite hard to read as well (please do take Bretana's advice to
heart!) this is about all I can say. If you need more advice, you'll have
to provide more information. Check out www.aspfaq.com/5006.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Help optimising SQL Query

Hi,
I have a problem I would really appreciate help with. I am generating
dynamic SQL and need to optimise it. The specific example I am trying to
optimise looks like this:

SELECT DISTINCT DataHeaderID FROM TB_DataDetailText T1 WHERE
(EntityFieldID IN ( 31) AND (Data LIKE '12BORE%' )) AND
(DataHeaderID=(SELECT DISTINCT DataHeaderID FROM TB_DataDetailText CT2
WHERE T1.DataHeaderID = CT2.DataHeaderID AND (EntityFieldID IN ( 34)
AND (Data LIKE 'SIDE BY SIDE%' )) ))AND
(DataHeaderID=(SELECT DISTINCT DataHeaderID FROM TB_DataDetailText CCT3
WHERE T1.DataHeaderID = CCT3.DataHeaderID AND (( Data LIKE 'church%' ))))

I was OK optimising it with just 2 criteria and changed:
SELECT DISTINCT DataHeaderID FROM TB_DataDetailText T1 WHERE

(EntityFieldID IN ( 31) AND (Data LIKE '12BORE%' )) AND

(DataHeaderID=(SELECT DISTINCT DataHeaderID FROM TB_DataDetailText CT2

WHERE T1.DataHeaderID = CT2.DataHeaderID AND (( Data LIKE 'church%' ))))

which took 26 seconds to using a derived table

SELECT distinct T1.DataHeaderID FROM TB_DataDetailText as T1

inner join (SELECT distinct DataHeaderID, Data FROM TB_DataDetailText )
CT2

on T1.DataHeaderID = CT2.DataHeaderID

WHERE

(T1.EntityFieldID IN ( 31) AND (T1.Data LIKE '12BORE%' ))

and (( CT2.Data LIKE 'church%' )) which took 0.03 seconds on the same data.

My problem is I need to write code to generate the SQL for 1 to n criteria
and am struggling to write the query for more than 2

Best regards,

AndrewCompletely untested...(I have two lovely young ladies ripping up some
cardboard behind me which is about an annoying a noise as you can get,
so if it's wrong, you have my excuse. I started on this before they
starting on the cardboard).

I've tried to tidy up your code a bit in the hopes that this points you
in a better direction for solving the problem with n criteria. Maybe
someone could take this further.

SELECT
T1.DataHeaderId

FROM
TB_DataDetailText T1
LEFT JOIN TB_DataDetailText CT2
ON T1.DataHeaderId = CT2.DataHeaderId
LEFT JOIN TB_DataDetailText CCT3
ON CT2.DataHeaderId = CCT3.DataHeaderId

WHERE
T1.EntityFieldId = 31 AND
T1.Data LIKE '12Bore% AND
CT2.EntityFieldId = 34 AND
CT2.Data LIKE 'Side By Side%' AND
CCT3.Data LIKE 'Church%'

Ryan|||Hi Ryan,

Thanks very much. Tidying it up like that makes it much more straightforward
to see what I should do. I have it cracked now and yes, that does work and
blindingly fast (there was a bit of a whinge about quotes but that may have
been me and was easily fixed). It also lets me see a second way that I can
do it.

Thanks again,

Andrew|||No problem.

Ryan

Andrew wrote:
> Hi Ryan,
> Thanks very much. Tidying it up like that makes it much more
straightforward
> to see what I should do. I have it cracked now and yes, that does
work and
> blindingly fast (there was a bit of a whinge about quotes but that
may have
> been me and was easily fixed). It also lets me see a second way that
I can
> do it.
> Thanks again,
> Andrew

Help Optimising SP

HI All,
I am busy importing records from excel into a SQL table.
I am using:
insert into PLImport2 select * from OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\work\coke\Detailed P&L June RE.xls', 'SELECT * FROM
[Import1]')
The excle sheet has 49000 records in it, which normally takes about 20-22
seconds, which includes opening the excel file of course.
Which normally
I have an instead of trigger, so that I can replace certain column on input.
With the trigger running it took 1:43:20
Could someone see if this could be optimised. Or is there a better way of
doing things.
Thanks
RObert
PS Below is the table and sp. Please dont worry too much about the field
name, ie [1], as this is how it was created when come over from excel.
This acts as a staging table , and will be put into the proper table once
all the validation is taken care of.
Thanks
CREATE TABLE [dbo].[PLImport2] (
[RowID] float NULL,
[PF] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PFDesc] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Acc] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Product] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[PostingPeriod] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[1] float NULL,
[2] float NULL,
[3] float NULL,
[4] float NULL,
[5] float NULL,
[6] float NULL,
[7] float NULL,
[8] float NULL,
[9] float NULL,
[10] float NULL,
[11] float NULL,
[12] float NULL,
[111] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[21] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[31] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[41] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[51] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[61] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[71] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[81] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[91] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[101] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[112] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[121] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[122] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[22] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[32] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[42] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[52] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[62] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[72] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[82] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[92] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[102] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[113] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[123] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[13] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[23] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[33] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[43] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[53] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[63] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[73] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[83] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[93] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[103] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[114] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[124] varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
ON [PRIMARY]
GO
CREATE TRIGGER [dbo].[PLImport2_tri] ON [dbo].[PLImport2]
WITH EXECUTE AS 'dbo'
INSTEAD OF INSERT
AS
BEGIN
--Declare some variables that we will use in the cursor
Declare @.profitcenter varchar(50), @.Acc varchar(75), @.pf varchar(50),
@.oldAcc varchar(75), @.RowID int, @.cnt int
set @.cnt = 1
--Declare the cursor and fetch records from inerted table
DECLARE OneChange CURSOR LOCAL READ_ONLY FORWARD_ONLY STATIC
FOR SELECT RowID, PF, Acc FROM inserted
OPEN OneChange
FETCH NEXT FROM OneChange INTO @.RowID, @.profitcenter, @.Acc
--loop thour the curso performing task on each record
WHILE (@.@.FETCH_STATUS=0)
BEGIN
-- If there are no records inserted already, insert at least one
if (select count(*) from plimport2) = 0
begin
insert into plimport2 select top 1 * from inserted
FETCH NEXT FROM OneChange INTO @.RowID, @.profitcenter, @.Acc
end
--now select the last inserted record, by getting the Max of field F!
select @.pf = PF, @.oldAcc = Acc from plimport2 where RowID = (select
max(RowID) from plimport2)
--compare the results if null, replace with old value
if @.pf is null
begin
print 'PF is null'
end
else
begin
insert into plimport2 select * from inserted i where i.RowID=@.RowID
if @.profitcenter is null
set @.profitcenter = @.pf
else
begin
set @.pf = @.profitcenter
end
update plimport2 set PF=@.profitcenter where PF is null
if @.Acc is null
set @.Acc = @.oldAcc
else
begin
set @.oldAcc = @.Acc
end
update plimport2 set Acc=@.Acc where Acc is null
print 'Pf - '+@.pf+' Profic Center = '+@.profitcenter+' Dep = '+@.Acc+'
Status = '+str(@.@.FETCH_STATUS)
end
set @.cnt = @.cnt+1
FETCH NEXT FROM OneChange INTO @.RowID, @.profitcenter, @.Acc
print 'next Status = '+str(@.@.FETCH_STATUS)
end
ENDRobert,
I would consider another alternative:
1. create a staging table and populate it from Excel:
select * into staging from OPENROWSET
2. issue one set-based UPDATE followed by one set-based insert. For
instance, try this:
[url]http://sql-server-tips.blogspot.com/2006/06/mimicking-merge-statement-in-sql.html[
/url]|||Hi There,
You should give sample data ,DDL and required result to work on.
I think you may try this as Alexander suggested (I am giving SQL 2000
version)
Update those rows taht exists
Update tableX set amt=amt+(Select a from tableY where
tablex.PKID=tabley.PKID) ,col2=xy,
col3=xz
where exists(Select a from tableY where tablex.PKID=tabley.PKID)
insert those rows that doesnot exists
insert into tableX (col1,col2,col3) Select * from tabley where Not
exists(Select a from tableY where tablex.PKID=tabley.PKID)
With Warm regards
Jatinder Singh
http://jatindersingh.blogspot.com
Alexander Kuznetsov wrote:
> Robert,
> I would consider another alternative:
> 1. create a staging table and populate it from Excel:
> select * into staging from OPENROWSET
> 2. issue one set-based UPDATE followed by one set-based insert. For
> instance, try this:
> http://sql-server-tips.blogspot.com...ent-in-sql.html[
/color]

Help optimising a stored proc

Hi I have the following procedure that accepts two CSV lists of values,
the first list contains primary key numbers, and the second values to
update.
When the list gets over about 200 items, I am getting intermittent
Timout errors.
Currently just over 500,000 records in the table.
Is there a way to optimise the performace of the update? Or is theer an
easier way if the input can be provided in a single list
e.g 2245=1,2257=2,3367=2 instead of
2245,2257,3367 and 1,2,2
Thanks!
CREATE Procedure dbo.UpdateResults
@.RegistrationIDs Varchar(8000),
@.Results Varchar(4000)
AS
UPDATE tblRegistrations
SET Result
= (SELECT A.Value FROM dbo.Split(@.Results,',') A
JOIN dbo.Split(@.RegistrationIDs,',') B ON A.id = B.id
WHERE RegistrationID=B.Value )
WHERE EXISTS (SELECT *
FROM dbo.Split(@.Results,',') A
JOIN dbo.Split(@.RegistrationIDs,',') B ON A.id = B.id
WHERE RegistrationID=B.Value)
CREATE FUNCTION dbo.Split
(
@.List varchar(8000),
@.SplitOn nvarchar(5)
)
RETURNS @.RtnValue table
(
Id int identity(1,1),
Value nvarchar(150)
)
AS
BEGIN
While (Charindex(@.SplitOn,@.List)>0)
Begin
Insert Into @.RtnValue (value)
Select
Value =
ltrim(rtrim(Substring(@.List,1,Charindex(
@.SplitOn,@.List)-1)))
Set @.List =
Substring(@.List,Charindex(@.SplitOn,@.List
)+len(@.SplitOn),len(@.List))
End
Insert Into @.RtnValue (Value)
Select Value = ltrim(rtrim(@.List))
Return
ENDI would try using temporary tables instead of table variables. I have seen
some strange stuff happen when trying to join two table variables together,
or joining a table-valued function together with a real base table.
Move the logic of the dbo.split funtion inside the stored procedure, take
the input csv strings and write them into a temporary table, then process
from that temp table.
"hals_left" wrote:

> Hi I have the following procedure that accepts two CSV lists of values,
> the first list contains primary key numbers, and the second values to
> update.
> When the list gets over about 200 items, I am getting intermittent
> Timout errors.
> Currently just over 500,000 records in the table.
> Is there a way to optimise the performace of the update? Or is theer an
> easier way if the input can be provided in a single list
> e.g 2245=1,2257=2,3367=2 instead of
> 2245,2257,3367 and 1,2,2
> Thanks!
>
> CREATE Procedure dbo.UpdateResults
> @.RegistrationIDs Varchar(8000),
> @.Results Varchar(4000)
> AS
> UPDATE tblRegistrations
> SET Result
> = (SELECT A.Value FROM dbo.Split(@.Results,',') A
> JOIN dbo.Split(@.RegistrationIDs,',') B ON A.id = B.id
> WHERE RegistrationID=B.Value )
> WHERE EXISTS (SELECT *
> FROM dbo.Split(@.Results,',') A
> JOIN dbo.Split(@.RegistrationIDs,',') B ON A.id = B.id
> WHERE RegistrationID=B.Value)
>
> CREATE FUNCTION dbo.Split
> (
> @.List varchar(8000),
> @.SplitOn nvarchar(5)
> )
> RETURNS @.RtnValue table
> (
> Id int identity(1,1),
> Value nvarchar(150)
> )
> AS
> BEGIN
> While (Charindex(@.SplitOn,@.List)>0)
> Begin
> Insert Into @.RtnValue (value)
> Select
> Value =
> ltrim(rtrim(Substring(@.List,1,Charindex(
@.SplitOn,@.List)-1)))
> Set @.List =
> Substring(@.List,Charindex(@.SplitOn,@.List
)+len(@.SplitOn),len(@.List))
> End
> Insert Into @.RtnValue (Value)
> Select Value = ltrim(rtrim(@.List))
> Return
> END
>|||Hi There,
What Mark suggested is right but you may like to try this .
UPDATE T1
SET Result = A.Value
>From FROM dbo.Split(@.Results,',') A
JOIN dbo.Split(@.RegistrationIDs,',') B ON A.id = B.id
Join tblRegistrations T1 On T1.RegistrationID=B.Value
and remove the split function If possible .
With Warm regards
Jatinder Singh
Mark Williams wrote:
> I would try using temporary tables instead of table variables. I have seen
> some strange stuff happen when trying to join two table variables together
,
> or joining a table-valued function together with a real base table.
> Move the logic of the dbo.split funtion inside the stored procedure, take
> the input csv strings and write them into a temporary table, then process
> from that temp table.
> --
> "hals_left" wrote:
>|||Thanks Jatinder, that works nice on a small test and is much simpler
SQL.
I'l test in on the real database and see how it compares to the
original
I dont really see how can I remove the split function, unless I pass
the data 1 record at a time in a loop ...

Help opening .MDF file

I'm trying to follow the article

http://aspnet.4guysfromrolla.com/articles/031506-1.aspx. It gives a sample to download at the bottom which I did. I'm trying to take a look at the Stored Proc that were created in the PagingData.mdf. The only thing included in the App_Data folder is PagingData.mdf file. How can I open the DB or attach it to my SQL2005 server? There is no .ldf file included in thesample so the attaching is failing.

You have two possible options connect the MDF to Management Studio and see if you can access everything or Backup and Restore the database SQL Server will receate everything including stored procs and LDF. Hope this helps.

http://blogs.msdn.com/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

|||

You can attach the MDF file to the SQL Server 2005 by using the simple command

SP_ATTACH_DB <Give your DB Name, any name is fine>,<Location of the DB file>

and programatically you can connect to the MDF file using code as described in

http://ambarishganguly.blogspot.com/2006/10/sql-server-express-xcopy.html

Hope this helps.

Thanks

Ambarish

sql

Help on XML Explicit

Hello, I am starting to work with XML Explicit. I am having problems
with the tags and the level they generate in.
Can anyone please help me, for I have looked aroung and it seems that I
am doing everything fine!!!
I am attaching below an example of the query and the XML it generates.
===========================
Declare @.IdCat int
set @.IdCat = 62
SELECT
1 AS TAG,
NULL AS PARENT,
'' AS [p!1],
NULL AS [pc!2],
NULL AS [pc!2!npc!xml],
NULL AS [pc!2!idp!xml],
NULL AS [pc!2!nc!xml],
NULL AS [pc!2!m!xml],
NULL AS [e!3!xml],
NULL AS [e!3!ce!xml],
NULL AS [e!3!de!xml],
NULL AS [e!3!fe!xml]
FROM tDE_Cataporte DE_Cat
WHERE DE_Cat.IdCat = @.IdCat
UNION ALL
SELECT
2 AS TAG,
1 AS PARENT,
NULL AS [p!1],
'' AS [pc!2],
DE_Pl.NumPlaCli AS [pc!2!npc!xml],
DE_Pl.IdPla AS [pc!2!idp!xml],
DE_Pl.NumCta AS [pc!2!nc!xml],
DE_Pl.Monto AS [pc!2!m!xml],
NULL AS [e!3!xml],
NULL AS [e!3!ce!xml],
NULL AS [e!3!de!xml],
NULL AS [e!3!fe!xml]
FROM tDE_Planilla DE_Pl
WHERE DE_Pl.IdCat = @.IdCat
UNION ALL
SELECT
3 AS TAG,
2 AS PARENT,
NULL AS [p!1],
NULL AS [pc!2],
NULL AS [pc!2!npc!xml],
NULL AS [pc!2!idp!xml],
NULL AS [pc!2!nc!xml],
NULL AS [pc!2!m!xml],
'' AS [e!3!xml],
DE_Est.CodEst AS [e!3!ce!xml],
DE_Est.DesEst AS [e!3!de!xml],
DE_PlEstObs.FecEst AS [e!3!fe!xml]
FROM tDE_PlanillaxEstado_Observacion DE_PlEstObs INNER JOIN
tDE_Planilla DE_Pl ON DE_PlEstObs.IdPla =
DE_Pl.IdPla INNER JOIN
tDE_Estado DE_Est ON DE_PlEstObs.CodEst =
DE_Est.CodEst
WHERE DE_Pl.IdCat = @.IdCat
AND DE_PlEstObs.FecEst = (SELECT MIN(DE_PlEstObs2.FecEst) FROM
tDE_PlanillaxEstado_Observacion DE_PlEstObs2 WHERE
DE_PlEstObs2.IdPla=DE_Pl.IdPla)
FOR XML Explicit
<p>
<pc>
<npc>888</npc>
<idp>58</idp>
<nc>9939</nc>
<m>20000</m>
</pc>
<pc>
<npc>555</npc>
<idp>60</idp>
<nc>00018</nc>
<m>131150</m>
</pc>
<pc>
<npc>753</npc>
<idp>61</idp>
<nc>20018</nc>
<m>40300</m>
<e xml="">
<ce>0</ce>
<de>Borrador</de>
<fe>2005-07-07T16:06:04.130</fe>
</e>
<e xml="">
<ce>0</ce>
<de>Borrador</de>
<fe>2005-07-08T10:40:12.390</fe>
</e>
<e xml="">
<ce>0</ce>
<de>Borrador</de>
<fe>2005-07-08T11:39:32.830</fe>
</e>
</pc>
</p>
========================================
==================
As you can see the tag 3 (<e xml=""> is only generated at the end when
there should be one <e> for each <pc>.
Thank you in advance for your help.Please post DDL and some sample data. Can't guess your data.
ML

HELP ON XML

Hi all,
I have a small query, may be this is not supported in SQL 2000. But at least
I want some round about way, which will solve my problem. I am here pasting
working code.
DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT *
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
This Query will give me result
CustomerID ContactName
-- --
VINET Paul Henriot
LILAS Carlos Gonzlez
This is fine but I want to get results like this.
COLONE
‘Customer CustomerID="VINET" ContactName="Paul Henriot”’
‘Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"’
Please suggest me some ways to achieve this
TIA,
KISHORHello,
Try this (obvious) query:
DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT 'Customer CustomerID="'+CustomerID
+'" ContactName="'+ContactName+'"' AS COLONE
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
Is this what you need ?
Razvan|||Hi Razvan,
Thanxs But this will not work. what I actually want is to get all inner
attribute of a xml. here you are concating ContactName...but I dont want to
have a hardcoding like this. client can pass Name , Cname...any thing. I jus
t
want a list of all all attribute.
I have tried this also
DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT CustomerID ,ContactName
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20)
)
for xml auto
But gave me error
Unnamed column or table names cannot be used as XML identifiers. Name
unnamed columns using AS in the SELECT statement.
Regards,
Kishor
"Razvan Socol" wrote:

> Hello,
> Try this (obvious) query:
> DECLARE @.idoc int
> DECLARE @.doc varchar(1000)
> SET @.doc ='
> <ROOT>
> <Customer CustomerID="VINET" ContactName="Paul Henriot">
> </Customer>
> <Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
> </Customer>
> </ROOT>'
>
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
> SELECT 'Customer CustomerID="'+CustomerID
> +'" ContactName="'+ContactName+'"' AS COLONE
> FROM OPENXML (@.idoc, '/ROOT/Customer',1)
> WITH (CustomerID varchar(10),
> ContactName varchar(20))
> Is this what you need ?
> Razvan
>|||> here you are concating ContactName...
> but I dont want to have a hardcoding like this.
You already did hardcoding: in the parameters of the OPENXML function,
in the WITH clause.

> I have tried this also [...] for xml auto [...] But gave me error
[...]
Try this:
[...]
SELECT * INTO #tmp
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
SELECT * FROM #tmp FOR XML AUTO
DROP TABLE #tmp
Razvan|||Yes,
Just to explain you all I have done .. I just want inner attributes...
if you know .. let me know.
TIA
Kishor
"Razvan Socol" wrote:

> You already did hardcoding: in the parameters of the OPENXML function,
> in the WITH clause.
>
> [...]
> Try this:
> [...]
> SELECT * INTO #tmp
> FROM OPENXML (@.idoc, '/ROOT/Customer',1)
> WITH (CustomerID varchar(10),
> ContactName varchar(20))
> SELECT * FROM #tmp FOR XML AUTO
> DROP TABLE #tmp
> Razvan
>

HELP ON XML

Hi all,
I have a small query, may be this is not supported in SQL 2000. But at least
I want some round about way, which will solve my problem. I am here pasting
working code.
DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT *
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
This Query will give me result
CustomerID ContactName
-- --
VINET Paul Henriot
LILAS Carlos Gonzlez
This is fine but I want to get results like this.
COLONE
‘Customer CustomerID="VINET" ContactName="Paul Henriot”’
‘Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"’
Please suggest me some ways to achieve this
TIA,
KISHORIf what you want is the <Customer> element with all attributes, then you can
use this code:
SELECT *
FROM OPENXML (@.idoc, '/ROOT/Customer',2)
WITH (Customer varchar(100) '@.mp:xmltext')
This will return the following 2 rows:
<Customer CustomerID="VINET" ContactName="Paul Henriot"></Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"></Customer>
On the other hand, if you want the literal strings you specified in your
post, you could do it by just concatenating the values from the resultset
like this:
SELECT nodeName + ' CustomerID ="' + CustomerID + '" ContactName=' +
ContactName + '"'
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (nodeName varchar(10) '@.mp:localname',
CustomerID varchar(10),
ContactName varchar(20))
This gives you these 2 rows:
Customer CustomerID ="VINET" ContactName=Paul Henriot"
Customer CustomerID ="LILAS" ContactName=Carlos Gonzlez"
(you could just specify a literal "Customer" instead of retrieving the node
name like I've done.)
Cheers,
Graeme
Graeme Malcolm
Principal Technologist
Content Master
- a member of CM Group Ltd.
www.contentmaster.com
"kishor" <kishor@.discussions.microsoft.com> wrote in message
news:C42D06A8-C961-4730-A9C7-A5940F401649@.microsoft.com...
Hi all,
I have a small query, may be this is not supported in SQL 2000. But at least
I want some round about way, which will solve my problem. I am here pasting
working code.
DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
</Customer>
</ROOT>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT *
FROM OPENXML (@.idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20))
This Query will give me result
CustomerID ContactName
-- --
VINET Paul Henriot
LILAS Carlos Gonzlez
This is fine but I want to get results like this.
COLONE
'Customer CustomerID="VINET" ContactName="Paul Henriot"'
'Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"'
Please suggest me some ways to achieve this
TIA,
KISHOR|||Hi Graeme Malcolm,
Thanxs for your solution, This worked ...
'@.mp:xmltext'
Regards,
Kishor.
"Graeme Malcolm" wrote:

> If what you want is the <Customer> element with all attributes, then you c
an
> use this code:
> SELECT *
> FROM OPENXML (@.idoc, '/ROOT/Customer',2)
> WITH (Customer varchar(100) '@.mp:xmltext')
> This will return the following 2 rows:
> <Customer CustomerID="VINET" ContactName="Paul Henriot"></Customer>
> <Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"></Customer>
> On the other hand, if you want the literal strings you specified in your
> post, you could do it by just concatenating the values from the resultset
> like this:
> SELECT nodeName + ' CustomerID ="' + CustomerID + '" ContactName=' +
> ContactName + '"'
> FROM OPENXML (@.idoc, '/ROOT/Customer',1)
> WITH (nodeName varchar(10) '@.mp:localname',
> CustomerID varchar(10),
> ContactName varchar(20))
> This gives you these 2 rows:
> Customer CustomerID ="VINET" ContactName=Paul Henriot"
> Customer CustomerID ="LILAS" ContactName=Carlos Gonzlez"
> (you could just specify a literal "Customer" instead of retrieving the nod
e
> name like I've done.)
> Cheers,
> Graeme
> --
> Graeme Malcolm
> Principal Technologist
> Content Master
> - a member of CM Group Ltd.
> www.contentmaster.com
>
> "kishor" <kishor@.discussions.microsoft.com> wrote in message
> news:C42D06A8-C961-4730-A9C7-A5940F401649@.microsoft.com...
> Hi all,
> I have a small query, may be this is not supported in SQL 2000. But at lea
st
> I want some round about way, which will solve my problem. I am here pastin
g
> working code.
> DECLARE @.idoc int
> DECLARE @.doc varchar(1000)
> SET @.doc ='
> <ROOT>
> <Customer CustomerID="VINET" ContactName="Paul Henriot">
> </Customer>
> <Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
> </Customer>
> </ROOT>'
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc
> SELECT *
> FROM OPENXML (@.idoc, '/ROOT/Customer',1)
> WITH (CustomerID varchar(10),
> ContactName varchar(20))
> This Query will give me result
> CustomerID ContactName
> -- --
> VINET Paul Henriot
> LILAS Carlos Gonzlez
> This is fine but I want to get results like this.
> COLONE
> 'Customer CustomerID="VINET" ContactName="Paul Henriot"'
> 'Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"'
> Please suggest me some ways to achieve this
> TIA,
> KISHOR
>
>
>