Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Monday, March 26, 2012

Optimized way to store hashed values?

What is the most optimized way to store Hashed values (obtained by Object.GetHashCode() method) in SQL Server?Thanks.Theres gotta be a way :(|||

What are you trying to accomplish? Object.GetHashCode() returns an int, so why wouldn't you store it as an int? But why would you want to do this?

|||Well I should have explained my question first. Sorry. I have a big long feild of string values that are unique. Insted of storing those string values I thouht that storing the Hascode will be faster. Since there will be gazillions of these values I just wanted to find out what would be the most optimized way to store them. The process to store values in the database will occur once a day but searching using this value would be a very common thing (over 14000 potential users). So would it be best to store it as int or perheps bytes or something else which is even faster :)Thanks for your help.|||

Interesting idea. Well, I don't think GetHashCode is what you want. Reading fromhttp://msdn2.microsoft.com/en-us/library/system.object.gethashcode.aspx,

"The default implementation of theGetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does not guarantee the default implementation of theGetHashCode method, and the value it returns will be the same between different versions of the .NET Framework. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes."

There are other hashing mechanisms in .Nets crypto libraries that you should checkhttp://msdn2.microsoft.com/en-us/library/system.security.cryptography(VS.71).aspx. I don't know whether they have the same issues but one of the ideas of hashing is that even very large inputs return very small hashes

Optimize the Query

Listed below is tsql statement that I set up execute every 60 minutes.
To check to see if all the values exist in the following list: '806478',
'806479','806480','806481' in the Call_Movements table.
I am only interest in the first six characters and I'm converting iNum data
type from money to varchar(20).
left(cast(iNum as varchar(20)),6)
Please help me optimize the t-sql statement listed below since this table is
large.
Is there away to change the following to binary format:
DECLARE @.CNT_MTN_REC_0 SMALLINT and change the following t-sql statement
listed below to be optimal?
Thank You,
T-SQL
DECLARE @.CNT_MTN_REC_0 SMALLINT
SET @.CNT_MTN_REC_0 =
(Select count(iNum)
from Call_Movements
where DATEDIFF(mi, Start_Time, GETDATE()) <=60
AND left(cast(iNum as varchar(20)),6) = ('806478'))
--
-- Count the
--
DECLARE @.CNT_MTN_REC_1 SMALLINT
SET @.CNT_MTN_REC_1 =
(Select count(iNum)
from Call_Movements
where DATEDIFF(mi, Start_Time, GETDATE()) <=60
AND left(cast(iNum as varchar(20)),6) = ('806479'))
--
--
--
DECLARE @.CNT_MTN_REC_2 SMALLINT
SET @.CNT_MTN_REC_2 =
(Select count(iNum)
from Call_Movements
where DATEDIFF(mi, Start_Time, GETDATE()) <=60
AND left(cast(iNum as varchar(20)),6) = ('806480'))
--
--
--
DECLARE @.CNT_MTN_REC_3 SMALLINT
SET @.CNT_MTN_REC_3 =
(Select count(iNum)
from Call_Movements
where DATEDIFF(mi, Start_Time, GETDATE()) <=60
AND left(cast(iNum as varchar(20)),6) = ('806481'))
--
--
--
if (@.CNT_MTN_REC_0 = 0) OR (@.CNT_MTN_REC_1 = 0) OR (@.CNT_MTN_REC_2 = 0) OR
(@.CNT_MTN_REC_3 = 0)
BEGIN
PRINT "Error has Occurred'
ENDJoe K. (Joe K.@.discussions.microsoft.com) writes:
> To check to see if all the values exist in the following list: '806478',
> '806479','806480','806481' in the Call_Movements table.
> I am only interest in the first six characters and I'm converting iNum
> data type from money to varchar(20).
> left(cast(iNum as varchar(20)),6)
> Please help me optimize the t-sql statement listed below since this
> table is large.
> Is there away to change the following to binary format:
> DECLARE @.CNT_MTN_REC_0 SMALLINT and change the following t-sql statement
> listed below to be optimal?
It would have helped if you had posted the CREATE TABLE and CREATE INDEX
statements for the tables.
But first, there is no need to run four SQL statemennts.
This could either be done as:
Select count(iNum), left(cast(iNum as varchar(20)),6)
from Call_Movements
where StartTime >= DATEADD(mi, -60, GETDATE())
AND left(cast(iNum as varchar(20)),6) IN
('806478', '806479', '806480', '806481')
GROUP BY left(cast(iNum as varchar(20)),6)
This produces a result set of four rows. If you need to get the result
into variables, you can do:
Select @.CNT_MTN_REC_0 = SUM(CASE left(cast(iNum as varchar(20)),6)
WHEN '806478' THEN 1
ELSE 0
END),
..
from Call_Movements
where StartTime >= DATEADD(mi, -60, GETDATE())
AND left(cast(iNum as varchar(20)),6) IN
('806478', '806479', '806480', '806481')
As you can see, I have also changed the condition on Start_Time, in case
this column is indexed. When an indexed column appears in an expression
like in your query, the index is of on use. The query is still problematic
due to the >=. If the index on StartTime is clustered it is not much of
an issue, but if there is only a onn-clustered index, the optimizer is not
likely to pick it in this case.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Joe,
Will you have iNum values that start with 806478 (or any of the other 3
values) followed by other numbers before the decimal point? For example
8064781.01?
If not, then make sure you add a nonclustered index on
Call_Movement(iNum, StartTime) and add the following predicates to the
WHERE clause:
AND iNum >= 806478
AND iNum < 806482
You could try the following query:
IF ( SELECT COUNT(DISTINCT CAST(iNum as char(6)) )
FROM Call_Movements
WHERE StartTime >= DATEADD(minute, -60, CURRENT_TIMESTAMP)
AND iNum >= CAST(806478 AS money)
AND iNum < CAST(806482 AS money)
AND CAST(iNum as char(6)) IN ('806478', '806479', '806480',
'806481')
) < 4
BEGIN
PRINT "Error has Occurred'
END
HTH,
Gert-Jan
Joe K. wrote:
> Listed below is tsql statement that I set up execute every 60 minutes.
> To check to see if all the values exist in the following list: '806478',
> '806479','806480','806481' in the Call_Movements table.
> I am only interest in the first six characters and I'm converting iNum dat
a
> type from money to varchar(20).
> left(cast(iNum as varchar(20)),6)
> Please help me optimize the t-sql statement listed below since this table
is
> large.
> Is there away to change the following to binary format:
> DECLARE @.CNT_MTN_REC_0 SMALLINT and change the following t-sql statement
> listed below to be optimal?
> Thank You,
>
> T-SQL
> DECLARE @.CNT_MTN_REC_0 SMALLINT
> SET @.CNT_MTN_REC_0 =
> (Select count(iNum)
> from Call_Movements
> where DATEDIFF(mi, Start_Time, GETDATE()) <=60
> AND left(cast(iNum as varchar(20)),6) = ('806478'))
> --
> -- Count the
> --
> DECLARE @.CNT_MTN_REC_1 SMALLINT
> SET @.CNT_MTN_REC_1 =
> (Select count(iNum)
> from Call_Movements
> where DATEDIFF(mi, Start_Time, GETDATE()) <=60
> AND left(cast(iNum as varchar(20)),6) = ('806479'))
> --
> --
> --
> DECLARE @.CNT_MTN_REC_2 SMALLINT
> SET @.CNT_MTN_REC_2 =
> (Select count(iNum)
> from Call_Movements
> where DATEDIFF(mi, Start_Time, GETDATE()) <=60
> AND left(cast(iNum as varchar(20)),6) = ('806480'))
> --
> --
> --
> DECLARE @.CNT_MTN_REC_3 SMALLINT
> SET @.CNT_MTN_REC_3 =
> (Select count(iNum)
> from Call_Movements
> where DATEDIFF(mi, Start_Time, GETDATE()) <=60
> AND left(cast(iNum as varchar(20)),6) = ('806481'))
> --
> --
> --
> if (@.CNT_MTN_REC_0 = 0) OR (@.CNT_MTN_REC_1 = 0) OR (@.CNT_MTN_REC_2 = 0) OR
> (@.CNT_MTN_REC_3 = 0)
> BEGIN
> PRINT "Error has Occurred'
> END|||And encapsulate LEFT operation to sub-query may be get more good
performance.
Gert-Jan Strik =E5=86=99=E9=81=93=EF=BC=9A
> Joe,
> Will you have iNum values that start with 806478 (or any of the other 3
> values) followed by other numbers before the decimal point? For example
> 8064781.01?
> If not, then make sure you add a nonclustered index on
> Call_Movement(iNum, StartTime) and add the following predicates to the
> WHERE clause:
> AND iNum >=3D 806478
> AND iNum < 806482
> You could try the following query:
> IF ( SELECT COUNT(DISTINCT CAST(iNum as char(6)) )
> FROM Call_Movements
> WHERE StartTime >=3D DATEADD(minute, -60, CURRENT_TIMESTAMP)
> AND iNum >=3D CAST(806478 AS money)
> AND iNum < CAST(806482 AS money)
> AND CAST(iNum as char(6)) IN ('806478', '806479', '806480',
> '806481')
> ) < 4
> BEGIN
> PRINT "Error has Occurred'
> END
>
> HTH,
> Gert-Jan
>
> Joe K. wrote:
data
le is
=3D 0) OR|||"navyzhu@.gmail.com" wrote:
> And encapsulate LEFT operation to sub-query may be get more good
> performance.
I have not done performance tests to disprove it, but I highly doubt it!
I don't think LEFT will outperform CAST.
Besides, why use the proprietary LEFT when the standard CAST will do
just fine...
Gert-Jan
> Gert-Jan Strik 写道:
>

Friday, March 23, 2012

Optimize Query

I need some help with optimizing this qry... The table tbl2, in the field dfrsloanno, has values such as 100024PRP and 10024.. ie some records are with the letters PRP at the end, and some records are without. Hence when I join ths tbl2 with tbl1 table, I have to join on both the occureences, ie look for the recs with the PRP and the ones without it too.

My qry howver, runs for a long time, ie 22 seconds, when I use the one below.

select dfrsloanno, a.* from tbl1 a
left join tbl2 comm
on (convert(varchar,a.acct#))=SubString(COMM.[dfrsloanno], 0, PatIndex('%[A-Z,a-z]%', COMM.[dfrsloanno]))


or ltrim(rtrim(COMM.[dfrsloanno])) =ltrim(rtrim(convert(varchar,a.acct#)))

However, when I take out the or criteria, it runs for only 2 seconds .. The reason I have the or crtieria is to meet both the scenarios ie 10024PRP and 10024... Hence I need the OR criteria. But I foudn that the culprit of the slowness in the qry is the OR condition...

Pl advise, how can I optimze this, and keep the OR condition too?

When you wrap various functions around column values, you negate the possibility of using any indexing on that column and the entire table must be scanned.

Is it possible to add a computed column (that could be indexed) that would be without the 'PRP'?

|||This worked very well. I did jsut like u suggested. On my tbl2, I put case statements, to tae into account both the PRP and without PRP. Then this qry returned results in 3 secs only.That is what I needed. Thanks

Monday, March 12, 2012

Optimal "set and forget" values?

Is there an optimum "set and forget" value for automatic range identity?
Set it and forget it is best when you know you are never going to add new
subscribers.
When you set it you want to use values which are going to be valid for the
lifetime of your replication solution. So for high throughput solutions, it
could be in the millions; for low throughput solutions it could be in the
10's of thousands.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Earl" <brikshoe@.newsgroups.nospam> wrote in message
news:OyRHOV8aFHA.3280@.TK2MSFTNGP09.phx.gbl...
> Is there an optimum "set and forget" value for automatic range identity?
>
|||I have a merge solution which could have as many as 50 PocketPCs (unlikely)
or as few as 5-6. Right now, I'm using an identity increment of 1 and an
identity range of 1,000,000 for both the publisher and the subscriber. The
typical subscriber would add maybe 200 records (per table) on a day, merge
changes back to the main SQL database, then delete the subscription at the
client. So I suppose that this really becomes an unlimited number of
subscribers, since a new subscription is sent down every day? I'm trying to
forecast the future here and it seems pretty murky to me. Thanks for the
advice.
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:Oi9ZZn8aFHA.1148@.tk2msftngp13.phx.gbl...
> Set it and forget it is best when you know you are never going to add new
> subscribers.
> When you set it you want to use values which are going to be valid for the
> lifetime of your replication solution. So for high throughput solutions,
> it
> could be in the millions; for low throughput solutions it could be in the
> 10's of thousands.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Earl" <brikshoe@.newsgroups.nospam> wrote in message
> news:OyRHOV8aFHA.3280@.TK2MSFTNGP09.phx.gbl...
>
|||you should be good for 2,147,483,648/1,000,000 -1 (to account for the
publisher) or roughly 2,146 subscribers. If all goes well and if you expect
less than 1 million rows to be added on your publisher and each subscriber
for the lifetime of your replication solution.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Earl" <brikshoe@.newsgroups.nospam> wrote in message
news:edYmcA%23aFHA.2288@.TK2MSFTNGP14.phx.gbl...
> I have a merge solution which could have as many as 50 PocketPCs
(unlikely)
> or as few as 5-6. Right now, I'm using an identity increment of 1 and an
> identity range of 1,000,000 for both the publisher and the subscriber. The
> typical subscriber would add maybe 200 records (per table) on a day, merge
> changes back to the main SQL database, then delete the subscription at the
> client. So I suppose that this really becomes an unlimited number of
> subscribers, since a new subscription is sent down every day? I'm trying
to[vbcol=seagreen]
> forecast the future here and it seems pretty murky to me. Thanks for the
> advice.
>
> "Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
> news:Oi9ZZn8aFHA.1148@.tk2msftngp13.phx.gbl...
new[vbcol=seagreen]
the[vbcol=seagreen]
the[vbcol=seagreen]
identity?
>
|||Thanks Hilary. My expectation is for less than 1 million rows on both
publisher and subscribers. One thing that still concerns me however -- when
I delete on-board databases (subscribers) and create anew, doesn't this
indeed create a new subscriber and eat up one of my "2,146 subscribers"?
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:%23enx9fBbFHA.3840@.tk2msftngp13.phx.gbl...
> you should be good for 2,147,483,648/1,000,000 -1 (to account for the
> publisher) or roughly 2,146 subscribers. If all goes well and if you
> expect
> less than 1 million rows to be added on your publisher and each subscriber
> for the lifetime of your replication solution.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Earl" <brikshoe@.newsgroups.nospam> wrote in message
> news:edYmcA%23aFHA.2288@.TK2MSFTNGP14.phx.gbl...
> (unlikely)
> to
> new
> the
> the
> identity?
>
|||yes, when you create a new subscriber, whether the pda had an old one before
or not, the max identity value on the publisher will be updated. This max
value is consulted when incrementing an existing range or assigning a new
one.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Earl" <brikshoe@.newsgroups.nospam> wrote in message
news:%23hY8tbHbFHA.3848@.TK2MSFTNGP10.phx.gbl...
> Thanks Hilary. My expectation is for less than 1 million rows on both
> publisher and subscribers. One thing that still concerns me however --
when[vbcol=seagreen]
> I delete on-board databases (subscribers) and create anew, doesn't this
> indeed create a new subscriber and eat up one of my "2,146 subscribers"?
> "Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
> news:%23enx9fBbFHA.3840@.tk2msftngp13.phx.gbl...
subscriber[vbcol=seagreen]
an[vbcol=seagreen]
trying[vbcol=seagreen]
the[vbcol=seagreen]
for
>
|||Very helpful Hilary. Now I just need to make a minor change to my app so as
to ensure I do not have any long-term issues with the number of subscribers.
I've estimated that -- in most scenarios -- I would've run out of identity
ranges in about a year otherwise.
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:%23YPrULJbFHA.2380@.tk2msftngp13.phx.gbl...
> yes, when you create a new subscriber, whether the pda had an old one
> before
> or not, the max identity value on the publisher will be updated. This max
> value is consulted when incrementing an existing range or assigning a new
> one.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "Earl" <brikshoe@.newsgroups.nospam> wrote in message
> news:%23hY8tbHbFHA.3848@.TK2MSFTNGP10.phx.gbl...
> when
> subscriber
> an
> trying
> the
> for
>

Saturday, February 25, 2012

OpenXML XPath question

I've included the xml and my OpenXML statement below. Using XPath in the
WITH portion of the OpenXML statement I can retrieve most values I need, but
I am trying to retrieve the values 'Last Name of Client' and 'First Name of
Client' from the xml and am not having any luck. I tried using '..' as the
xpath query but that returns text in the Question node and all child nodes.
<Section Value="AA"> Name and Identification Numbers
<Question Value="1.A"> Last Name of Client
<Question_Text>Last</Question_Text>
<Answer_Text>ROSSI1</Answer_Text>
<Answer_Value>ROSSI2</Answer_Value>
</Question>
<Question Value="2.A"> First Name of Client
<Question_Text>First Name</Question_Text>
<Answer_Text>TestA1</Answer_Text>
<Answer_Value>TestA2</Answer_Value>
</Question>
</Section>
OpenXML(@.idoc, '/ns0:GoldCare_Assessment/Section/Question')
WITH ([SectionValue] varchar(50) '../@.Value',
[QuestionValue] varchar(50) '@.Value',
[Question_Text] varchar(50) './Question_Text',
[Answer_Text] varchar(50) './Answer_Text',
[Answer_Value] varchar(50) './Answer_Value')Look at the bottom of this article where the stored procedure is shown:
http://www.eggheadcafe.com/articles...er_bulkload.asp
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.mastervb.net/home/ng/for...st10017013.aspx
http://www.eggheadcafe.com/articles...e_generator.asp
"Jeremy Chapman" <NoSpam@.Please.com> wrote in message
news:e1us7sSGFHA.2756@.TK2MSFTNGP15.phx.gbl...
> I've included the xml and my OpenXML statement below. Using XPath in the
> WITH portion of the OpenXML statement I can retrieve most values I need,
> but
> I am trying to retrieve the values 'Last Name of Client' and 'First Name
> of
> Client' from the xml and am not having any luck. I tried using '..' as
> the
> xpath query but that returns text in the Question node and all child
> nodes.
> <Section Value="AA"> Name and Identification Numbers
> <Question Value="1.A"> Last Name of Client
> <Question_Text>Last</Question_Text>
> <Answer_Text>ROSSI1</Answer_Text>
> <Answer_Value>ROSSI2</Answer_Value>
> </Question>
> <Question Value="2.A"> First Name of Client
> <Question_Text>First Name</Question_Text>
> <Answer_Text>TestA1</Answer_Text>
> <Answer_Value>TestA2</Answer_Value>
> </Question>
> </Section>
> OpenXML(@.idoc, '/ns0:GoldCare_Assessment/Section/Question')
> WITH ([SectionValue] varchar(50) '../@.Value',
> [QuestionValue] varchar(50) '@.Value',
> [Question_Text] varchar(50) './Question_Text',
> [Answer_Text] varchar(50) './Answer_Text',
> [Answer_Value] varchar(50) './Answer_Value')
>
>

Monday, February 20, 2012

OPENXML question

I am using the OpenXml command and I have a question (XML posted below)...
I don't know how to get the values of certain elements if they columns
needed are not attributes to the XML...
For instance I can get the value of /attributes/items for the type attribute
but if I try to get the values of the /attributes/items/item elements it
returns null.
'<attributes>
<lot>E070484</lot>
<from-location type="dock">AA01</from-location>
<dest-location type="dock">AA05</dest-location>
<items type="yarn">
<item>QP35990</item>
<item>QP36134</item>
</items>
</attributes>'
JITry the following:
SELECT *
FROM OPENXML ( @.idoc, '/attributes/items/item',2 )
with
([Value] varchar(100) '.')
Q
"JI" wrote:

> I am using the OpenXml command and I have a question (XML posted below)...
> I don't know how to get the values of certain elements if they columns
> needed are not attributes to the XML...
> For instance I can get the value of /attributes/items for the type attribu
te
> but if I try to get the values of the /attributes/items/item elements it
> returns null.
> '<attributes>
> <lot>E070484</lot>
> <from-location type="dock">AA01</from-location>
> <dest-location type="dock">AA05</dest-location>
> <items type="yarn">
> <item>QP35990</item>
> <item>QP36134</item>
> </items>
> </attributes>'
>
> --
> JI|||Try,
use northwind
go
declare @.idoc int
declare @.doc varchar(1000)
set @.doc ='<attributes>
<lot>E070484</lot>
<from-location type="dock">AA01</from-location>
<dest-location type="dock">AA05</dest-location>
<items type="yarn">
<item>QP35990</item>
<item>QP36134</item>
</items>
</attributes>'
exec sp_xml_preparedocument @.idoc OUTPUT, @.doc
SELECT
*
FROM
OPENXML (@.idoc, '/attributes/items/item')
with (item varchar(10) '/attributes/items/item')
EXEC sp_xml_removedocument @.idoc
"JI" wrote:

> I am using the OpenXml command and I have a question (XML posted below)...
> I don't know how to get the values of certain elements if they columns
> needed are not attributes to the XML...
> For instance I can get the value of /attributes/items for the type attribu
te
> but if I try to get the values of the /attributes/items/item elements it
> returns null.
> '<attributes>
> <lot>E070484</lot>
> <from-location type="dock">AA01</from-location>
> <dest-location type="dock">AA05</dest-location>
> <items type="yarn">
> <item>QP35990</item>
> <item>QP36134</item>
> </items>
> </attributes>'
>
> --
> JI

OPENXML question

I've got thousands of XML docs and have to import those to the DB. And
I am having problem with getting some values because of tricky XML
format.

I didn't create this XML format and I don't like this format, OOP snob
did. And I(DBA) have to look after their mess.
I've got XML doc like this :
<customer>
<customer_id>12345</customer_id>
<first_name>Jason</first_name>
<last_name>Varitek</last_name>
<location>
<city>Boston</city>
<state>MA</state>
</location>
</customer
First, I did following :

DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<customer>
<customer_id>12345</customer_id>
<first_name>Jason</first_name>
<last_name>Varitek</last_name>
<location>
<city>Boston</city>
<state>MA</state>
</location>
</customer>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc

SELECT *
FROM OPENXML (@.idoc, '/customer',2)
WITH (customer_id int,
first_name varchar(50),
last_name varchar(50),
location varchar(50))

Then returned this which is not bad.

customer_id | first_name |last_name |location
12345 | Jason | Varitek |Boston MA

But I need to return city and state in separated columns(I wish OOP
snobs made these as attributes in location element, instead of
elements). And I tried following and returned everything NULL.

DECLARE @.idoc int
DECLARE @.doc varchar(1000)
SET @.doc ='
<customer>
<customer_id>12345</customer_id>
<first_name>Jason</first_name>
<last_name>Varitek</last_name>
<location>
<city>Boston</city>
<state>MA</state>
</location>
</customer>'

EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc

SELECT *
FROM OPENXML (@.idoc, '/customer/customer_id',2)
WITH (customer_id int '../@.customer_id',
first_name varchar(50) '../@.first_name',
last_name varchar(50) '../@.last_name',
city varchar(50) '@.city',
state varchar(50) '@.state')

Does anybody have any idea to get value of city & state elements in
separated columns?

Thanks

JimmySELECT *
FROM OPENXML (@.idoc, '/customer',2)
WITH (customer_id int,
first_name varchar(50),
last_name varchar(50),
city varchar(50) './location/city',
state varchar(50) './location/state')|||Thanks.