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

  • SEARCH
  • Home
  • 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 6804339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:27:13+00:00 2026-05-26T19:27:13+00:00

I created one stored procedure; it executed successfully but while executing manually it is

  • 0

I created one stored procedure; it executed successfully but while executing manually it is showing error.

Here’s my stored proc

USE [chandru]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter procedure [dbo].[Insert_BandWidthDetails]          
@CurrentState nvarchar(50),@Process nvarchar(100),@DateTime nvarchar(100),@IPaddress nvarchar(50),@UploadedBytes nvarchar(max),@DownloadedBytes nvarchar(max),@Duration nvarchar(200),@FileSize nvarchar(max),@StreamId nvarchar(100),@PlayerId nvarchar(100),
@UserName nvarchar(200),@UserId nvarchar(200),@CountryName nvarchar(100),@RegionName nvarchar(100),@Latitude nvarchar(100),@Longitude nvarchar(100),@City nvarchar(100)           
as          
begin    


declare @Sql nvarchar(max)     

set @Sql='declare @countbandwidthtable int  select @countbandwidthtable=COUNT(*) from BandWidth'+@UserName+@UserId+
   +'if(@countbandwidthtable>0)
    begin
        declare @count int  select @count=COUNT(*) from BandWidth'+@UserName+@UserId+' where CurrentState='''+@CurrentState+''' and Process='''+@Process+''' and DateTime='''+@DateTime+''' and IPaddress='''+@IPaddress+''' and UploadedBytes='''+@UploadedBytes+''' and DownloadedBytes='''+@DownloadedBytes+''' and Duration='''+@Duration+''' and FileSize='''+@FileSize+''' and StreamId='''+@StreamId+''' and PlayerId='''+@PlayerId+''' and UserName='''+@UserName+''
        +'if(@count=0)          
        begin          
            insert into BandWidth'+@UserName+@UserId+' values('''+@CurrentState+''','''+@Process+''','''+@DateTime+''','''+@IPaddress+''','''+@UploadedBytes+''','''+@DownloadedBytes+''','''+@Duration+''','''+@FileSize+''','''+@StreamId+''','''+@PlayerId+''','''+@UserName+''','''+@CountryName+''','''+@RegionName+''','''+@Latitude+''','''+@Longitude+''','''+@City+''')       
        end         
    end
else
    begin
        select * into BandWidth'+ @UserName+ cast(@UserID as nvarchar(max)) +' from BandWidthSample where 1=2
       insert into BandWidth'+@UserName+@UserId+' values('''+@CurrentState+''','''+@Process+''','''+@DateTime+''','''+@IPaddress+''','''+@UploadedBytes+''','''+@DownloadedBytes+''','''+@Duration+''','''+@FileSize+''','''+@StreamId+''','''+@PlayerId+''','''+@UserName+''','''+@CountryName+''','''+@RegionName+''','''+@Latitude+''','''+@Longitude+''','''+@City+''')      
    end '     
 exec(@Sql)
end

After execution of this stored procedure, command is successfully and now I am inserting:

Insert_BandWidthDetails 'stream','play','11:17:00','10.0.3.0','12344','1234','2.09','22','1','11223','sample','31','india','asd','23','23','chennai'

I am getting the error

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘>’.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ‘stream’
Msg 105, Level 15, State 1, Line 11
Unclosed quotation mark after the character string ‘) end ‘.

I don’t know how to clear this error, I didn’t find any error near ‘>’ this symbol, can you guys help me out to clear this error?

  • 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-05-26T19:27:14+00:00Added an answer on May 26, 2026 at 7:27 pm

    Besides the design where you have a single table per user, your issue is that the first line of SQL doesn’t have a space before the IF statement. If you want line breaks in the SQL, then you need to add + CHAR(10) and not have the line breaks directly in the code.

    If you are keeping the dynamic SQL, I would suggest reformatting it the set statement as follows:

    set @Sql='declare @countbandwidthtable int' + CHAR(10) + 
             'select @countbandwidthtable=COUNT(*) from BandWidth' + @UserName + @UserId + CHAR(10) +
             'if(@countbandwidthtable>0)' + CHAR(10) +
               'begin' + CHAR(10) +
                 'declare @count int' + CHAR(10) +
                 'select @count=COUNT(*) from BandWidth'+@UserName+@UserId+' where CurrentState='''+@CurrentState+''' and Process='''+@Process+''' and DateTime='''+@DateTime+''' and IPaddress='''+@IPaddress+''' and UploadedBytes='''+@UploadedBytes+''' and DownloadedBytes='''+@DownloadedBytes+''' and Duration='''+@Duration+''' and FileSize='''+@FileSize+''' and StreamId='''+@StreamId+''' and PlayerId='''+@PlayerId+''' and UserName='''+@UserName+'' + CHAR(10) +
                 'if(@count=0)' + CHAR(10) +
                   'begin' + CHAR(10) +
                     'insert into BandWidth'+@UserName+@UserId+' values('''+@CurrentState+''','''+@Process+''','''+@DateTime+''','''+@IPaddress+''','''+@UploadedBytes+''','''+@DownloadedBytes+''','''+@Duration+''','''+@FileSize+''','''+@StreamId+''','''+@PlayerId+''','''+@UserName+''','''+@CountryName+''','''+@RegionName+''','''+@Latitude+''','''+@Longitude+''','''+@City+''')' + CHAR(10) +
                   'end' + CHAR(10) +
               'end' + CHAR(10) +
             'else' + CHAR(10) +
               'begin' + CHAR(10) +
                 'select * into BandWidth'+ @UserName+ cast(@UserID as nvarchar(max)) +' from BandWidthSample where 1=2' + CHAR(10) +
                 'insert into BandWidth'+@UserName+@UserId+' values('''+@CurrentState+''','''+@Process+''','''+@DateTime+''','''+@IPaddress+''','''+@UploadedBytes+''','''+@DownloadedBytes+''','''+@Duration+''','''+@FileSize+''','''+@StreamId+''','''+@PlayerId+''','''+@UserName+''','''+@CountryName+''','''+@RegionName+''','''+@Latitude+''','''+@Longitude+''','''+@City+''')' + CHAR(10) +
                'end' + CHAR(10)
    

    However, I would strongly encourage you, if possible, to just have a single BandWidth table that contains columns that hold the UserName and UserId. Then you won’t have to have dynamic SQL at all.

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

Sidebar

Related Questions

I've created a stored procedure similar to the one below (I'm using this cut
One of our programs is erroring out because a stored procedure was created with
I have multiple tables . I have created one stored procedure where I am
For one of our recent projects, we created a stored procedure which generated SQL
Can any one tell me if its possible to create a stored procedure in
I created one application to read all the contacts stored in android 2.0 emulator.I
I need to create a stored proc that will return records (more than one
I created one GWT webapplication project.Inthat i want to create servlet program,but in that
I created a stored procedure that has 9 inserts in summarized tables and the
Another developer created a stored procedure that is set up to run as a

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.