我创建了一个存储过程;它执行成功,但手动执行时显示错误。我创建了一个存储过程,但执行没有错误,但手动运行它显示错误
这里是我的存储过程
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,Level 15,State 1,Line 1
'>'附近语法不正确。
消息102,级别15,状态1,行邻近 '流'
消息105,级别15,状态1 5
的语法不正确,行字符串 ')' 末端后11
闭合的引号。
我不知道如何清除这个错误,我在'>'这个符号附近没有发现任何错误,你们可以帮我解决这个错误吗?
注释掉exec(@sql)语句并添加一个print @Sql语句。您的声明将打印在消息窗口中。复制语句并尝试在新的查询窗口中运行该语句。您应该能够轻松地看到语法错误,特别是在使用智能感知的情况下。 – brian
感谢其工作 – user1005078