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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Error on Stored Procedure

Author  Topic 

suresh_dotnet
Starting Member

6 Posts

Posted - 2008-09-29 : 20:02:05
Hi:
I have writtern a Stored procedure in which have taken a Bigint value and insert it into another table.
while running the query i met an error.I have mentioned my Stored procedure and the error i have met below.


Stored Procedure:


ALTER PROCEDURE [dbo].[DAMS_SP_InsertUserDetails]




@UserName as varchar(25),
@FirstName as varchar(100),
@LastName as varchar(100),
@DateOfBirth as datetime,
@StreetAddress1 as varchar(1000),
@StreetAddress2 as varchar(1000),
@City as varchar(250),
@State as varchar(250),
@CountryId as int,
@Email as varchar(250),
@PhoneNo as varchar(25),
@MobileNo as varchar(25),
@FaxNo as varchar(25),
@EmailDigestFrequency as char(25),
@AreaOfInterest as int,
@InvoiceDeliveryMethod as varchar(25)

AS

BEGIN

SET NOCOUNT ON;

DECLARE @sqlinsert nvarchar(100)

SET @sqlinsert=''
SET @sqlinsert=@sqlinsert+'SELECT UserId FROM DAMS_Tbl_UsersLogin WHERE UserName='''+@UserName+''''
EXEC @sqlinsert

INSERT INTO DAMS_Tbl_RegisteredUsers(UserId,FirstName,LastName,DateOfBirth ,StreetAddress1 ,StreetAddress2 ,

City,State ,CountryId ,Email ,PhoneNo,MobileNo,FaxNo ,EmailDigestFrequency,AreaOfInterest ,InvoiceDeliveryMethod )VALUES

(cast (@sqlinsert as Bigint) ,@FirstName,@LastName,@DateOfBirth ,@StreetAddress1 ,@StreetAddress2 ,@City,@State ,@CountryId ,@Email,

@PhoneNo,@MobileNo,@FaxNo ,@EmailDigestFrequency,@AreaOfInterest ,@InvoiceDeliveryMethod )

END


Error:

System.Data.SqlClient.SqlException: Could not find stored procedure 'SELECT UserId FROM DAMS_Tbl_UsersLogin WHERE UserName='jhon''.
Error converting data type nvarchar to bigint.


Since its very very urgent
Can any one send me query or give me a suggestion to solve this issue.

Thanks





suresh

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-29 : 20:04:54
EXEC (@sqlinsert)

But why are you using dynamic SQL for this when it isn't needed?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ursangel
Starting Member

17 Posts

Posted - 2008-10-29 : 11:49:53
when executing a dynamic sql use sp_executesql and then the string value
eg:- exec sp_executesql @sqlinsert

Replace that line and execute the SP.
BTW there is no need to use a dynamic sql in this place.

Regards
Angel
Go to Top of Page
   

- Advertisement -