Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:05:33+00:00 2026-06-02T13:05:33+00:00

I am currently working on a project that involves generating sequences using stored procedures

  • 0

I am currently working on a project that involves generating sequences using stored procedures in Entity Framework. I was using Code Project article here, and upon attempting to generate the following stored procedure, I received a syntax error:

SET QUOTED_IDENTIFIER OFF

GO 
SET ANSI_NULLS OFF
GO 

CREATE PROCEDURE DBO.p_GetNextInSequence 
    @SequenceKey VARCHAR(20)
AS 
BEGIN 
SET NOCOUNT ON 
DECLARE @LASTNUMBER INT
DECLARE @NEXTNUMBER INT
DECLARE @FORMATTEDNUMBER VARCHAR(40)
DECLARE @MYKEY VARCHAR(30)

IF NOT EXISTS(SELECT 'X' 
              FROM SequenceControl 
              WHERE SequenceControl.SequenceKey = @SequenceKey )
BEGIN 
    SELECT    @SequenceKey AS SequenceKey, 
              CAST('' AS VARCHAR(30)) AS NextSequenceFormatted, 
              CAST(0 AS INT) AS NextSequenceInt 
    RETURN 
END 

DECLARE @SEQFORMAT VARCHAR(30), @IncrementBy INT, 
                   @IncrementStep INT, @zeropadtodigits INT

SELECT @SEQFORMAT = RTRIM(LTRIM(SequenceFormat)),
       @IncrementBy = IncrementBy, 
       @zeropadtodigits = ZeroPadToDigits 
FROM    SequenceControl 
WHERE    SequenceControl.SequenceKey = @SequenceKey 

DECLARE @THEROWCOUNT INT 
SET @THEROWCOUNT    = 0 

BEGIN TRANSACTION T1
    WHILE ( @THEROWCOUNT =0 ) 
    BEGIN 
        SELECT   @LASTNUMBER= LastSequence 
        FROM     SequenceControl
        WHERE    SequenceControl.SequenceKey= @SequenceKey 

        UPDATE     SequenceControl 
        SET        LastSequence = @LASTNUMBER + @IncrementBy 
        WHERE      SequenceKey = @SequenceKey AND    
                   LastSequence = @LASTNUMBER 

        SELECT @THEROWCOUNT = @@ROWCOUNT
    END 
COMMIT TRANSACTION T1 

--SQL Complains near this region...
DECLARE @FMTNUM VARCHAR(20) 
SET @NEXTNUMBER = @LASTNUMBER + @IncrementBy 
IF ( @zeropadtodigits>0) 
    SET @FMTNUM = ( REPLICATE('0', @zeropadtodigits) + 
                    CAST(@NEXTNUMBER AS VARCHAR(20)), @zeropadtodigits) 
ELSE 
    SET @FMTNUM = CAST(@NEXTNUMBER AS VARCHAR(10)) 


SET @FORMATTEDNUMBER = REPLACE(@SEQFORMAT,'[#]', @FMTNUM ) 

SELECT    @SequenceKey AS SequenceKey, 
          CAST(@FORMATTEDNUMBER AS VARCHAR(30)) AS NextSequenceFormatted, 
          @NEXTNUMBER AS NextSequenceInt 
END 

GO 
SET QUOTED_IDENTIFIER OFF
GO 
SET ANSI_NULLS ON    
GO

SQL is complaining about an incorrect syntax near ',' on Line 56:

DECLARE @FMTNUM VARCHAR(20) 

However – I can’t seem to figure out where or what is causing the issue. Also, if anyone has any suggestions or articles pertaining to using stored procedures within Entity Framework (and returning output) I would be appreciative.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:05:35+00:00Added an answer on June 2, 2026 at 1:05 pm

    The actual error is here:

    IF ( @zeropadtodigits>0) 
        SET @FMTNUM = ( REPLICATE('0', @zeropadtodigits) + 
                        CAST(@NEXTNUMBER AS VARCHAR(20)), @zeropadtodigits) 
    

    More specifically, here:

    , @zeropadtodigits)

    That comma doesn’t do anything, and @zeropadtodigits doesn’t apply to anything either. There’s no function using that as a parameter inside the parentheses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a project that I built using the alpha C4
im currently working on a project that involves listing contacts with a photo and
I'm currently working on a project that involves moving a database of documents for
I am currently working on a project that involves crawling certain websites. However sometimes
I'm working on a project that involves talking directly with Zebra printers. Currently, I
The project that I've been working on involves porting some old code. Right now
I am currently working on a project that involves splitting a url. I have
I'm currently working on a project that involves a CSV file. I initially was
A project I'm working on currently involves using a disparate set of technologies, including
So I'm currently working on a project that involves the collection and storing of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.