Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

xml query datetime datatype problem while inserting to xml Expand / Collapse
Author
Message
Posted Saturday, March 02, 2013 2:57 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 183, Visits: 948
I have a query like

UPDATE a
SET oldRemarks1.modify('insert <Value_Py>{sql:column("b.collection_date")}</Value_Py>
after (/Root/Row[3]/Item)[1]') from b
where a.[Date]='31-May-2004' and a.sl_no=b.regkey_slno

Here collection_date is of datetime datatype.So while it is inserted to xml it will be like 2012-03-05T00:00:00.000 in the xml tag.But i want to insert it as just "2012-03-05" in the xml tag. So how can i use cast or any other method here so that it will insert properly in xml.
Post #1425838
Posted Saturday, March 02, 2013 12:02 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 21,620, Visits: 27,453
winmansoft (3/2/2013)
I have a query like

UPDATE a
SET oldRemarks1.modify('insert <Value_Py>{sql:column("b.collection_date")}</Value_Py>
after (/Root/Row[3]/Item)[1]') from b
where a.[Date]='31-May-2004' and a.sl_no=b.regkey_slno

Here collection_date is of datetime datatype.So while it is inserted to xml it will be like 2012-03-05T00:00:00.000 in the xml tag.But i want to insert it as just "2012-03-05" in the xml tag. So how can i use cast or any other method here so that it will insert properly in xml.


Easiest answer, don't. Store the date in the proper data format, which is what is happening. If you must store it in a character format (not a good idea), then store it using a character data type.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1425882
Posted Tuesday, March 05, 2013 10:43 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 183, Visits: 948
I can't change the datatype from datetime to date.So is there any method like cast or anything?
Post #1427171
Posted Wednesday, March 06, 2013 4:41 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 7:39 AM
Points: 21,620, Visits: 27,453
winmansoft (3/5/2013)
I can't change the datatype from datetime to date.So is there any method like cast or anything?


Then think of this like the datetime data type in SQL. You may want to store only '2012-03-05' in the column but when ever you query the column you see '2012-03-05 00:00:00.000'. The XML data type is the same way. It is still going to have a time portion to it.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1427305
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse