Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 31st, 2006, 01:24 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default error in query

i am trying to run a stored procedure and there is a problem in this particular code


DECLARE @MidVchar char(10), @DOBdate smalldatetime, @PreId int

Select @MidVchar = datename(yy, getdate()) + 'FRE'
Select @PreId = max(MemberCodeint) from LoginRegFree

Select @MidVchar = @MidVchar & @PreId

and the error message is
Server: Msg 245, Level 16, State 1, Line 6
Syntax error converting the varchar value '2006FRE ' to a column of data type int.


Here MemberCodeint is type int (as identity)
and @MidVchar is Varchar

thanks in advance

ashok sharma

Reply With Quote
  #2 (permalink)  
Old March 31st, 2006, 01:49 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

First the "&" is a bitwise operator. If you are trying to concatenate strings you use "+"
Second you are trying to concatenate a char var (@MidVhar) with an integer (@PreID)
you need to convert the interger var
Something like
Select @MidVchar = @MidVchar + convert(varchar(10),@PreId)

Jim




Reply With Quote
  #3 (permalink)  
Old March 31st, 2006, 03:26 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default

i have already tried this, the query is running but result is unexpedted

as per query the result must be 2006FRE1 ----- PreId = 1
but the result is 2006FRE ----- PreId is not concanated

and there is no error

ashok

Reply With Quote
  #4 (permalink)  
Old March 31st, 2006, 10:56 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

what do you mean there is no error, your post says there is an error..

What are you trying to do?

Reply With Quote
  #5 (permalink)  
Old April 3rd, 2006, 01:20 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default

Hi,

i mean to say the changes you told to make, i changed. and after that there is no error but the result is unexpected.

i changed my code to
DECLARE @MidVchar char(10), @DOBdate smalldatetime, @PreId int

Select @MidVchar = datename(yy, getdate()) + 'FRE'
Select @PreId = max(MemberCodeint) from LoginRegFree
Select @MidVchar = @MidVchar + convert(varchar(10),@PreId)


as per query the result must be 2006FRE1 ----- PreId = 1
but the result is 2006FRE ----- PreId is not concanated



ashok

Reply With Quote
  #6 (permalink)  
Old April 3rd, 2006, 01:30 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Norway.
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

You need to change @MidVchar from char(10) to varchar(10) or varchar(what-ever-number-you-need).

Gert

Reply With Quote
  #7 (permalink)  
Old April 3rd, 2006, 03:23 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default

thanks gert

Probem Solved

can you tell me now how can i add preceeding zeros. for example when i run my sp the result is 2006FRE1 BUT i want it like
2006FRE00001

so how to add preceeding zeros in my @PreId (the length of this field is 5 character means till 99999)


thanks
ashok

Reply With Quote
  #8 (permalink)  
Old April 3rd, 2006, 08:03 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Norway.
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again.

Maybe something like this?

Select @MidVchar = @MidVchar + RIGHT('00000'+convert(varchar(10),@PreId),5)

Gert


Reply With Quote
  #9 (permalink)  
Old April 3rd, 2006, 11:32 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Nice one Gert!

Reply With Quote
  #10 (permalink)  
Old April 4th, 2006, 02:16 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default

hi Gert

great solution

thanks
ashok

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
error in query capri SQL Server 2000 5 April 4th, 2008 01:27 AM
Query Error Louisa VB.NET 2002/2003 Basics 5 August 9th, 2006 03:44 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM



All times are GMT -4. The time now is 12:23 PM.


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