Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2008, 04:19 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default @hDoc syntax error

Hi All

I have written one stored procedure and getting syntax error. I m posting just
a part of my stored procedure

set @strNonSwipeDts= ''''+REPLACE(@strNonSwipeDts,',',''',''')+''''

set @str = 'update leave_application
         set
              leave_code=current1.leave_code,leave_ampm=current1 .leave_ampm,
              status=current1.status,
              from_date = current1.from_date,
              to_date = current1.to_date,
              duration=cast(current1.duration as varchar),
              report_to=cast(current1.ReportingID as varchar)
        from openxml('+ cast(@hDoc as varchar) +',''/NewDataSet/current1'',2)
        with(Empno varchar(10),leave_refno varchar(10),leave_code varchar(10),leave_ampm varchar(10),
        status char(2),from_date varchar(50),to_date varchar(50),duration varchar(50),Reporting_To varchar(10),ReportingID varchar(10))current1
        WHERE
        leave_application.empno ='''+ @empno +''' and
        leave_date in ('+ @strNonSwipeDts +')' + ''
        print(@str)
        exec(@str)


i have declared everything. This is just part of my stored procedure where the error lies(syntax error)

error is : Incorrect syntax near '185'

185 is the @hDoc here. Please advice where syntactically i went wrong.


 
Old May 28th, 2008, 07:35 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't think you can cast a number to a varchar the way you are doing it. I would use the STR() function instead. You'll need to trim it after the conversion or you'll have extra spaces in the result.

-Peter
compiledthoughts.com
 
Old May 28th, 2008, 08:49 AM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Peter

I used STR() as you advised. This is what i changed----
from openxml(' +ltrim(cast(str(@hDoc) as varchar)) +',''/NewDataSet/current1'',2)

but it is still throwing the same error.
What else can be done.

 
Old May 28th, 2008, 09:33 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are you sure 185 is the value for @hDoc and not @empno? Assuming that leave_application.empno is a numeric field, this line doesn't look right:

  leave_application.empno ='''+ @empno +''' and

You are wrapping what I assume is a numeric value in quotes. Try removing the quotes:

  leave_application.empno ='+ @empno +' and

-Peter
compiledthoughts.com
 
Old May 28th, 2008, 11:32 PM
Authorized User
 
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Peter

yeah, it is the value for @hDoc only. I removed the quotes but still again the same error. This is what i get when i execute (@str)

------------- this is generated due to print(@str)-------------------------------
update leave_application
         set
              leave_code=current1.leave_code,leave_ampm=current1 .leave_ampm,
              status=current1.status,
              from_date = current1.from_date,
              to_date = current1.to_date,
              duration=cast(current1.duration as varchar),
              report_to=cast(current1.ReportingID as varchar)
        from openxml(265,'/NewDataSet/current1',2)

        with(Empno varchar(10),leave_refno varchar(10),leave_code varchar(10),leave_ampm varchar(10),
        status char(2),from_date varchar(50),to_date varchar(50),duration varchar(50),Reporting_To varchar(10),ReportingID varchar(10))current1
        WHERE
        leave_application.empno ='1214' and
        leave_date in ('08/09/2004','08/24/2004')
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near '265'.

(0 row(s) affected)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
VB Error: Syntax Error or Access Violation codehappy VB How-To 7 October 3rd, 2007 05:41 PM
Compile error: Syntax error: & Else without HELP Corey VB How-To 2 April 21st, 2006 03:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.