Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jim65
Starting Member
35 Posts |
Posted - 2006-03-10 : 10:37:46
|
| when run this stored procedures I got the error message which is "Syntax error converting the varchar value 'NULL' to a column of data type int."Any Idea will be helpfulCREATE PROCEDURE dbo.asp_InsertBorrowerfromCDB (@CustNum varchar(30), @UserID varchar(7)) ASINSERT INTO adBorrower (BorrowerName, BorrowerMainAdress, BorrowerZip, ClosingDate, LenderEnumber, ProposedTCC, BankID, CustNum, RiskRatingID)SELECT CustNam, CustAddr, CustZip, EstablishDt, @UserID, NetExposure, BankNum, CustNum, RiskRatingFROM CDB.dbo.tblCustomerWhere CustNum = @Custnum--get my new record IDDeclare @NewRecord intSELECT @NewRecord = @@Identity-- Inserts the Borrower as the default Entity ID (Main Contact) into adBorrowerEntityINSERT INTO adBorrowerEntity (BorrowerID, Title, MainContact, TypeID, ContactAddress, ContactZipCode, ContactCustNum)select @NewRecord, CustNam, '1', '1', CustAddr, CustZip, @CustNumFROM CDB.dbo.tblCustomerWhere CustNum = @CustnumGO |
|
|
JoeNak
Constraint Violating Yak Guru
292 Posts |
Posted - 2006-03-10 : 10:57:52
|
| If this is the complete procedure, it's tough to tell exactly where your implicit conversion is happening. You may have to go through tblCustomer to find 'NULL's. You could either update your table to change 'NULL's to NULL or build a case statement for that field for the insert statementOf course, I'm not sure why you'd store the string 'NULL' as a value.BTW, you should use SCOPE_IDENTITY for retreiving the last ID. @@IDENTITY returns the last identity value regardless of scope. |
 |
|
|
jim65
Starting Member
35 Posts |
Posted - 2006-03-10 : 12:05:14
|
| Thanks a lot. I found the value RiskRating(varchr) FROM table tblCustomer may be NULL. RiskRatingID(int) from adBorrower table.after I changed the SP, I got another error message "Syntax error converting the varchar value 'N' to a column of data type int."CREATE PROCEDURE dbo.asp_InsertBorrowerfromCDB (@CustNum varchar(30), @UserID varchar(7)) ASDeclare @newRiskID varcharDeclare @RiskID int SELECT @newRiskID = RiskRating FROM CDB.dbo.tblCustomerWhere CustNum = @Custnumif @newRiskID = NULLset @RiskID = 0else set @RiskID = CAST(@newRiskID AS int)INSERT INTO adBorrower (BorrowerName, BorrowerMainAdress, BorrowerZip, ClosingDate, LenderEnumber, ProposedTCC, BankID, CustNum, RiskRatingID)SELECT CustNam, CustAddr, CustZip, EstablishDt, @UserID, NetExposure, BankNum, CustNum, @RiskIDFROM CDB.dbo.tblCustomerWhere CustNum = @CustnumGO |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-03-11 : 11:51:13
|
| "Declare @newRiskID varchar"You need a size for the varchar definition"set @RiskID = CAST(@newRiskID AS int)"This is probably where the problem is arising. Is RiskRating in CDB.dbo.tblCustomer a VARCHAR rather than an INT?If so you probably need some sort of test to prove that it is number before you attempt casting it to INTKristen |
 |
|
|
|
|
|
|
|