Advertisement

04.14.2008 at 12:13AM PDT, ID: 23319534
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Comparing TIMESTAMP column in SQL Server 2005

Asked by batchakamal in SQL Server 2005, Extensible Markup Language (XML)

Tags: , , ,

Hi,

We are receiving a XML document as input to update the records in a table. Inorder to update the data we are using the Primary Key columns (Identity Column) and a timestamp column.

As part of the process, we are loading the XML data into a temporary table. When we load we are loading the timestamp column into a varchar column to get the same timestamp value, otherwise if we load into timestamp data type column it is inserting some new value.

Now when we update the records using the update statement it is throwing an error message for implicit conversion. We have tried convert functions and cast function to convert the data while updating, but it is not working.

To simulate our problem, just run the attached script.

Advice accordingly.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
--To create the table
 
CREATE TABLE [dbo].[EMPLOYEE](
	[OBJECT_ID] [int] IDENTITY(1,1) NOT NULL,
	[EMPLOYEENAME] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[EMPLOYEESALARY] [int] NULL,
	[DEPTID] [int] NULL,
	[TMSTAMP] [timestamp] 
) ON [PRIMARY]
 
GO
 
 
--Inserting two records to update later
 
insert into EMPLOYEE(EMPLOYEENAME)
values('ABC')
 
insert into EMPLOYEE(EMPLOYEENAME)
values('XYZ')
 
--SP Content
 
DECLARE @XMLDocPointer INT,
@strXML xml,
@sql VARCHAR(8000)
---CODE TO GET THE NEWLY INSERTED VALUE
SET @strXML ='
<RECORD>
   <EMPLOYEE>
        <OBJECT_ID>1</OBJECT_ID>
        <EMPLOYEENAME>AAAA</EMPLOYEENAME>
		<TMSTAMP>0x0000000000000FA7</TMSTAMP>
	</EMPLOYEE>
	<EMPLOYEE>
		<OBJECT_ID>2</OBJECT_ID>
        <EMPLOYEENAME>ZZZZ</EMPLOYEENAME>
		<TMSTAMP>0x0000000000000FA8</TMSTAMP>
       
  </EMPLOYEE>
</RECORD>
'
EXEC sp_xml_preparedocument @XMLDocPointer OUTPUT, @strXML
 
SELECT * into #T_TEMP
FROM
OPENXML(@XMLDocPointer,'/RECORD/EMPLOYEE',2)
WITH (OBJECT_ID INT,EMPLOYEENAME VARCHAR(30), EMPLOYEESALARY INT,DEPTID INT,TMSTAMP varchar(50))
 
SELECT * FROM #T_TEMP
 
---ERROR IN THE BELOW UPDATE STATMENT WHEN COMPAREING THE TIMESTMAP(IN WHERE CONDITION)
UPDATE EMPLOYEE
SET EMPLOYEE.EMPLOYEENAME=B.EMPLOYEENAME
FROM EMPLOYEE, #T_TEMP B
WHERE EMPLOYEE.OBJECT_ID=B.OBJECT_ID AND EMPLOYEE.TMSTAMP=B.TMSTAMP
 
select * from EMPLOYEE
 
--SELECT convert(varbinary(8),TMSTAMP) as t FROM EMPLOYEE
 
drop table #T_TEMP
[+][-]04.14.2008 at 12:21AM PDT, ID: 21348122

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.14.2008 at 12:21AM PDT, ID: 21348124

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.14.2008 at 02:24AM PDT, ID: 21348613

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.14.2008 at 12:57PM PDT, ID: 21353245

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Server 2005, Extensible Markup Language (XML)
Tags: Microsoft, SQL Server, 2005, XML
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 3
Solution Grade: A
 
 
[+][-]09.16.2008 at 11:07AM PDT, ID: 22491335

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.20.2008 at 04:09PM PDT, ID: 22532076

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628