TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Schleid Alex
NA
361
48.3k
Calling stored procedure from another stored procedure in sqlserver
Oct 22 2020 7:23 PM
Hi,
I have the following stored procedure in a Sql Server Database
CREATE
PROCEDURE
[dbo].[UP_SELECT_PO_NUMBER]
@StoreBranchID
int
,
@mPurchaseOrderNumber NVARCHAR(13)
OUTPUT
AS
--DECLARE @StoreBranchID int
--SELECT @StoreBranchID = 4
--DECLARE @mPurchaseOrderNumber nvarchar(13)
DECLARE
@lpo
int
DECLARE
@mPO
int
SET
@mPurchaseOrderNumber=
''
SELECT
@mPO=
cast
(
right
(RTRIM(PurchaseOrderNumber),5)
as
int
) + 1
FROM
PurchaseOrder
WHERE
PurchaseOrderID = (
SELECT
Max
(purchaseOrderID)
FROM
purchaseorder
WHERE
storebranchID = @StoreBranchID)
SET
@lpo = LEN(@mPO)
WHILE(@lpo<>5 )
BEGIN
SET
@mPurchaseOrderNumber +=
'0'
SET
@lpo = @lpo + 1
END
SET
@mPurchaseOrderNumber =
'PO'
+
'-'
+
CONVERT
(NVARCHAR,
YEAR
(GETDATE())) +
'-'
+ @mPurchaseOrderNumber +
CONVERT
(nvarchar,@mPO)
RETURN
@mPurchaseOrderNumber
it is just return a variable
Now I am calling it withing another store procedure with the following command
DECLARE
@PON NVARCHAR(13)
EXEC
UP_SELECT_PO_NUMBER @StoreBranchID = 4, @mPurchaseOrderNumber = @PON
OUTPUT
;
print @PON
and I am getting
"Conversion failed when converting the nvarchar value 'PO-2020-00023' to data type int." error. I have no type int in the calling procedure
Can someone help me spot my mistake?
Thanks in advance
Reply
Answers (
3
)
Code to compare 2 database tables and count the difference?
How to secure asp.net core web application?