Advertisement

10.02.2007 at 12:30PM PDT, ID: 22867369
[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!

8.2

CASTING Error... 2000 and 2005 Different

Asked by jamestieman in MS SQL Server

Tags: , , ,

I get an error with SS2000 that I don't get with SS2005.  I used the same scripts below to create all 3 items on both systems.
*********************************************
NO ERROR ON SQL SERVER 2005:

ERROR ON SQL SERVER 2000:
(1 row(s) affected)
Server: Msg 245, Level 16, State 1, Procedure fnGenerateNewBoxId, Line 32
Syntax error converting the varchar value '*' to a column of data type int.
********************************************
TABLE:
CREATE TABLE [NewBoxId] (
      [ID] [int] IDENTITY (50290000, 1) NOT NULL ,
      [BoxId] [char] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [ordernum] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_NewBoxId_ordernum] DEFAULT (1),
      [dateCreated] [datetime] NOT NULL CONSTRAINT [DF_NewBoxId_dateCreated] DEFAULT (getdate()),
      [used] [bit] NOT NULL CONSTRAINT [DF_NewBoxId_used] DEFAULT (0)
) ON [PRIMARY]
GO

******************************************
QUERY:
exec usp_GetBoxNumber 1234567

********************************************
STORED PROCEDURE
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE  PROCEDURE [dbo].[usp_GetBoxNumber]
@ord varchar(10)
as
declare @myIdentity int
insert into dbo.NewBoxID (ordernum, used) Values (@ord, 0)

select @myIdentity=SCOPE_IDENTITY()

update dbo.NewBoxID set Boxid = dbo.fnGenerateNewBoxId(@myIdentity)
where ID = @myIdentity
*********************************************
FUNCTION:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE function [dbo].[fnGenerateNewBoxId]
(
@boxnumber int
)
Returns char(20)
as
Begin
      declare @fullstr as varchar(20)
      declare @checkdigit as varchar (20)
      declare @prefix as varchar(10)
      declare @work as varchar(20)
      declare @I as int
      declare @oddcounter as int
      declare @evencounter as int
      declare @cwork as int
      declare @oddtotal as int
      declare @eventotal as int
      declare @total as int

      set @oddcounter = 1
      set @evencounter = 2
      set @oddtotal = 0
      set @eventotal = 0
      set @prefix = '0000024964'
      set @work = RIGHT('000000000' + cast(@boxnumber as varchar(7)),9)
      set @fullstr = @prefix + @work
      set @I = len(@fullstr)

      while @oddcounter <= @I
      begin
            set @cwork = substring(@fullstr, @oddcounter, 1)
            --print @oddcounter
            --print @cwork
            set @oddtotal = @oddtotal + cast(@cwork as int)
            set @oddcounter = @oddcounter + 2

      end
      --select @oddtotal

      while @evencounter <= @I
            begin
                  set @cwork = substring(@fullstr, @evencounter, 1)
                  set @eventotal = @eventotal + cast(@cwork as int)
                  set @evencounter = @evencounter + 2
            end
      set @total = (@oddtotal * 3) + @eventotal
      set @cwork =  @total % 10
      if @cwork = 0
            begin
                  set @checkdigit = @cwork
            end
            else set @checkdigit = 10 - @cwork
      set @fullstr = @fullstr + @checkdigit
      Return(@fullstr)
End
--------------------------------Start Free Trial
[+][-]10.02.2007 at 01:30PM PDT, ID: 20001813

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.

 
[+][-]10.02.2007 at 02:28PM PDT, ID: 20002244

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

Zone: MS SQL Server
Tags: casting, sql, 2005, 2000
Sign Up Now!
Solution Provided By: assyst
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.02.2007 at 02:50PM PDT, ID: 20002412

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.

 
[+][-]10.02.2007 at 08:28PM PDT, ID: 20003830

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.

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