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 |
|
reddymade
Posting Yak Master
165 Posts |
Posted - 2004-11-23 : 16:29:10
|
| Can you please help, i am trying to get this search stored proc. to work.I am getting the following error: Server: Msg 207, Level 16, State 3, Line 1Invalid column name 'cnt3'.when i am trying to use this to execute my stored proc from query analyzer.DECLARE @ProgNO nvarchar(50)DECLARE @ProjNO nvarchar(50)DECLARE @ContractNO nvarchar(50)SET @ProgNO = nullSET @ProjNO = nullSET @ContractNO = 'cnt3'execute USP_Searchrecords2 @ProgNO,@ProjNO,@ContractNO**********************Stored procedure code***************CREATE PROCEDURE dbo.USP_Searchrecords2 (@ProgNO nvarchar(50), @ProjNO nvarchar(50), @ContractNO nvarchar(50))AS DECLARE @SQL varchar(1000)DECLARE @Sql1 varchar(2000)SET @SQL = 'SELECT * FROM Tab_ccsnetcn 'If @ProgNO IS NOT NULL BEGIN set @sql1 = 'WHERE ProgNO = ' + @ProgNO ENDIf @ProjNO IS NOT NULL BEGIN If @sql1 IS NOT NULL BEGIN set @sql1 = @sql1 + ' and ProjNO =' + @ProjNO END ELSE BEGIN set @sql1 = ' WHERE ProjNO =' + @ProjNO END END If @ContractNO IS NOT NULL BEGIN If @sql1 IS NOT NULL BEGIN set @sql1 = @sql1 + ' and ContractNO =' + @ContractNO END ELSE BEGIN set @sql1 = ' WHERE ContractNO =' + @ContractNO END ENDEXEC(@SQL+@Sql1)GO**********************Thank you very much. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|