Click here to Skip to main content
15,885,980 members
Home / Discussions / Database
   

Database

 
QuestionMySQL - Update a table from same table using SELECT Pin
Jassim Rahma16-Jul-16 11:54
Jassim Rahma16-Jul-16 11:54 
AnswerRe: MySQL - Update a table from same table using SELECT Pin
Mycroft Holmes16-Jul-16 13:38
professionalMycroft Holmes16-Jul-16 13:38 
AnswerRe: MySQL - Update a table from same table using SELECT Pin
User 1106097917-Jul-16 1:37
User 1106097917-Jul-16 1:37 
GeneralRe: MySQL - Update a table from same table using SELECT Pin
Jassim Rahma17-Jul-16 3:00
Jassim Rahma17-Jul-16 3:00 
GeneralRe: MySQL - Update a table from same table using SELECT Pin
User 1106097917-Jul-16 3:11
User 1106097917-Jul-16 3:11 
AnswerRe: MySQL - Update a table from same table using SELECT Pin
Bernhard Hiller18-Jul-16 21:18
Bernhard Hiller18-Jul-16 21:18 
GeneralRe: MySQL - Update a table from same table using SELECT Pin
Mycroft Holmes18-Jul-16 22:05
professionalMycroft Holmes18-Jul-16 22:05 
QuestionError: Conversion failed when converting the varchar value Pin
Richard Andrew x648-Jul-16 10:39
professionalRichard Andrew x648-Jul-16 10:39 
Error: 245

"Conversion failed when converting the varchar value 'AS' to data type int."

The problem is that I have no field or variable named "AS". So I am really stumped. The complete code of the stored procedure is below: (I have marked the location of the error with a comment.)

Do you have any idea what it's talking about? Thank you very much for any pointers in the right direction!

SQL
ALTER PROCEDURE [dbo].[spVendorUpdateVendor] 
-- Add the parameters for the stored procedure here
                                @VENDORID          INT,
                                @ACTIVE            BIT,
                                @COUNTRYID         INT,
                                @VENDORCODE        NVARCHAR(10),
                                @NAME              NVARCHAR(50),
                                @WEBSITE1          NVARCHAR(50),
                                @WEBSITE2          NVARCHAR(50),
                                @VIACODE           NVARCHAR(10),
                                @TERMS             SMALLINT,
                                @USECOMPCODE       BIT,
                                @DISCOUNTPERCENT   SMALLINT,
                                @DELETEDBYID       INT,     -- Pass 0 if not deleting the record
                                @DELETEDON         DATETIME,
                                @NONUS             BIT,
                                @NOTES             NVARCHAR(MAX)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
	BEGIN TRY
                                
        	IF EXISTS(SELECT ID FROM VENDOR_MASTER WHERE ID = @VENDORID)
                	BEGIN                                                  --<< SQL SERVER SAYS THE ERROR IS ON THIS LINE

			        IF (@DELETEDBYID > 0) AND (NOT EXISTS(SELECT USERID FROM USERS WHERE USERID = @DELETEDBYID))
                                	BEGIN
                                        	RETURN 2; -- DeletedById does not exist in USERS table
                                        END

                                IF (NOT EXISTS(SELECT * FROM COUNTRY_CODES CC WHERE CC.COUNTRYCODE = @COUNTRYID))
                                	BEGIN
                                        	RETURN 3; -- Country Code does not exist in COUNTRY_CODES table
                                        END

                                IF (NOT EXISTS(SELECT SHIPVIACODE FROM ORDER_HANDLE_MASTER_SHIPVIA_CODES WHERE SHIPVIACODE = @VIACODE))
                                        BEGIN
                                                RETURN 4; -- VIA CODE does not exist.
                                        END

                                UPDATE VENDOR_MASTER SET	ACTIVE          = @ACTIVE,
								COUNTRYID       = @COUNTRYID,
								VENDORCODE      = @VENDORCODE,
   								NAME            = @NAME,
								WEBSITE1        = @WEBSITE1,
								WEBSITE2        = @WEBSITE2,
								VIACODE         = @VIACODE,
								TERMS           = @TERMS,
								USECOMPCODE     = @USECOMPCODE,
								DISCOUNTPERCENT = @DISCOUNTPERCENT,
								DELETEDBYID     = @DELETEDBYID,
								DELETEDON       = @DELETEDON,
								NONUS           = @NONUS,
								NOTES           = @NOTES

                                WHERE ID = @VENDORID;
			END
		ELSE -- IF EXISTS VENDORID
                	BEGIN
                        	RETURN 1; -- VendorId does not exist in Vendor Master table
                        END
	END TRY

        BEGIN CATCH
        	SELECT  ERROR_NUMBER()		[ErrorNumber],
                        ERROR_PROCEDURE()   	[ErrorProcedure],
                        ERROR_LINE()            [ErrorLine],
                        ERROR_MESSAGE()         [ErrorMessage]

                RETURN ERROR_NUMBER();
 	END CATCH

	RETURN 0;
END




The difficult we do right away...
...the impossible takes slightly longer.


modified 8-Jul-16 16:46pm.

AnswerRe: Error: Conversion failed when converting the varchar value Pin
Jörgen Andersson8-Jul-16 12:37
professionalJörgen Andersson8-Jul-16 12:37 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Richard Andrew x648-Jul-16 12:44
professionalRichard Andrew x648-Jul-16 12:44 
AnswerRe: Error: Conversion failed when converting the varchar value Pin
Mycroft Holmes8-Jul-16 13:54
professionalMycroft Holmes8-Jul-16 13:54 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Richard Andrew x648-Jul-16 14:22
professionalRichard Andrew x648-Jul-16 14:22 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Mycroft Holmes8-Jul-16 21:21
professionalMycroft Holmes8-Jul-16 21:21 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Richard Andrew x649-Jul-16 4:27
professionalRichard Andrew x649-Jul-16 4:27 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Mycroft Holmes9-Jul-16 11:31
professionalMycroft Holmes9-Jul-16 11:31 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Richard MacCutchan8-Jul-16 22:50
mveRichard MacCutchan8-Jul-16 22:50 
GeneralRe: Error: Conversion failed when converting the varchar value Pin
Richard Andrew x649-Jul-16 4:28
professionalRichard Andrew x649-Jul-16 4:28 
Questionsql linq, data duplication on 1 particular record Pin
jkirkerx7-Jul-16 14:06
professionaljkirkerx7-Jul-16 14:06 
AnswerRe: sql linq, data duplication on 1 particular record Pin
jkirkerx8-Jul-16 8:03
professionaljkirkerx8-Jul-16 8:03 
QuestionData duplication on multiple fields Pin
VK195-Jul-16 9:19
VK195-Jul-16 9:19 
AnswerRe: Data duplication on multiple fields Pin
Jörgen Andersson5-Jul-16 11:14
professionalJörgen Andersson5-Jul-16 11:14 
AnswerRe: Data duplication on multiple fields Pin
Mycroft Holmes5-Jul-16 17:21
professionalMycroft Holmes5-Jul-16 17:21 
AnswerRe: Data duplication on multiple fields Pin
jonyj18-Jul-16 2:49
jonyj18-Jul-16 2:49 
GeneralSQL Transactions - Torn apart in old code Pin
HobbyProggy5-Jul-16 1:12
professionalHobbyProggy5-Jul-16 1:12 
GeneralRe: SQL Transactions - Torn apart in old code Pin
Marc Clifton5-Jul-16 1:15
mvaMarc Clifton5-Jul-16 1:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.