ストアドプロシージャを1つ作成しました。正常に実行されましたが、手動で実行中にエラーが表示されます。エラーを表示せずにストアドプロシージャを作成しましたが、エラーが発生して手動で実行しました
は、ここでは、このストアドプロシージャの実行後、私のストアドプロシージャ
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'[email protected][email protected]+
+'if(@countbandwidthtable>0)
begin
declare @count int select @count=COUNT(*) from BandWidth'[email protected][email protected]+' where CurrentState='''[email protected]+''' and Process='''[email protected]+''' and DateTime='''[email protected]+''' and IPaddress='''[email protected]+''' and UploadedBytes='''[email protected]+''' and DownloadedBytes='''[email protected]+''' and Duration='''[email protected]+''' and FileSize='''[email protected]+''' and StreamId='''[email protected]+''' and PlayerId='''[email protected]+''' and UserName='''[email protected]+''
+'if(@count=0)
begin
insert into BandWidth'[email protected][email protected]+' values('''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''')
end
end
else
begin
select * into BandWidth'+ @UserName+ cast(@UserID as nvarchar(max)) +' from BandWidthSample where 1=2
insert into BandWidth'[email protected][email protected]+' values('''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''','''[email protected]+''')
end '
exec(@Sql)
end
だ、コマンドが正常であると今私が挿入しています:
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'
が、私はエラー
メッセージを取得しています102、レベル15、状態1、行1
'>'付近の構文が正しくありません。
メッセージ102、レベル15、状態1、行 'ストリーム'
メッセージ105、レベル15、状態1に近い5
不適切な構文、11
閉じられていない引用符文字列 ')' 末端の後の行。
このエラーを解決する方法はわかりませんが、このシンボル付近でエラーが見つかりませんでした。このエラーをクリアするには手伝ってもらえますか?
exec(@sql)文をコメントアウトし、print @Sql文を追加してください。メッセージウィンドウに文が印刷されます。ステートメントをコピーし、新しいクエリウィンドウでそれを実行しようとします。特に、intellisenseを使用する場合は、構文エラーを簡単に確認できるはずです。 – brian
ありがとうございました – user1005078