Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-11 : 13:57:04
|
| Gurus,Here is My ProcCreate procedure dal @batch varchar(5),@subcode varchar(10),@pass int out,@fail int out,@total int outasdeclare @marbat varchar(10)declare @substat varchar(20)set @marbat='mark'+@batchset @substat=@subcode+'status'execute('select @pass = count(*) from '+@marbat+' where '+@substat+'= '+''' Pass''')execute('select @fail = count(*) from '+@marbat+' where '+@substat+'= '+''' Fail''')set @total=@pass+@failThis is My input listdeclare @pass intdeclare @fail intdeclare @total intexec dal '2004','IT1008',@pass out ,@fail out,@total outselect @passselect @failselect @totalI am getting the error Msg 137, Level 15, State 1, Line 1Must declare the scalar variable "@pass".Msg 137, Level 15, State 1, Line 1Must declare the scalar variable "@fail".I cant find out where is the error.. Am i wrong anywhere..?Please help meThanks Krishna |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-11 : 15:09:06
|
http://www.sommarskog.se/dynamic_sql.html E 12°55'05.25"N 56°04'39.16" |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-11 : 15:14:52
|
| I have modified somehow. but i am not getting the resultAlter procedure dal @batch varchar(5),@subcode varchar(10),@pass int out ,@fail int out,@total int outasdeclare @marbat varchar(10)declare @substat varchar(20)Declare @Sql nVarchar(1000),@result1 varchar(10)Select @result1 = 'pass'set @marbat='mark'+@batchset @substat=@subcode+'status'Declare @params nvarchar(4000), @params1 Varchar(1000)Select @Sql = ' Select @out = Count(*) from '+ @marbat +' where '+@substat +' = '+''''+@result1+''''Set @params = N'@result1 nVarchar(100) ,@out int'Exec SP_ExecuteSQL @SQL, @params,@result1 = 'Pass',@out outSelect @Total = @Total+@passdeclare @pass intdeclare @fail intdeclare @total intexec dal '2004','IT1008',@pass out ,@fail out,@total outselect @passselect @failselect @total |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2008-03-11 : 15:29:35
|
| Problem resolved.I got it. Alter procedure dal @batch varchar(5),@subcode varchar(10),@pass int out ,@fail int out,@total int outasdeclare @marbat varchar(10), @substat varchar(20), @passout Int, @Failout Int, @Sql nVarchar(1000), @result1 varchar(10), @result2 varchar(10), @params nvarchar(4000)Select @result1 = 'pass',@result2 = 'fail'set @marbat='mark'+@batchset @substat=@subcode+'status'Select @Sql = ' Select @out = Count(*) from '+ @marbat +' where '+@substat +' = '+''''+@result1+''''Set @params = N'@result1 nVarchar(100) ,@out int out 'Exec SP_ExecuteSQL @SQL, @params,@result1 = 'Pass',@out =@passout OutputSelect @pass = @passoutSelect @Sql = ' Select @out = Count(*) from '+ @marbat +' where '+@substat +' = '+''''+@result2+''''Set @params = N'@result2 nVarchar(100) ,@out int out 'Exec SP_ExecuteSQL @SQL, @params,@result2 = 'Fail',@out =@failout OutputSelect @Fail = @failoutSelect @Total = @fail+@pass |
 |
|
|
|
|
|
|
|