Wrox Programmer Forums
| 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 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
  #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

  #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




  #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

  #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?

  #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

  #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

  #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

  #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


  #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!

  #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



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





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