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 |
|
sqldoubt
Starting Member
17 Posts |
Posted - 2010-07-09 : 12:38:05
|
| I am trying to read data from flat file and delete/ update records in different tables. I am getting these errors:An expression of non-boolean type specified in a context where a condition is expected, near 'ID'.Incorrect syntax near '='.Need help...SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOGOCREATE PROCEDURE [dbo].[SP_DeleteData]ASBEGIN TRY -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statementsSET NOCOUNT ON;DECLARE @sql nvarchar(max)DECLARE @Count intDECLARE @currentRecords intDECLARE @Action nvarcharDECLARE @DBName nvarcharDECLARE @TableName nvarcharDECLARE @BatchID nvarcharDECLARE @StepID nvarchardeclare @controlvalue nvarchar(100)DECLARE @executeSQL nvarchar--Create Temporary Tables to read and hold the data from Text filesCREATE TABLE #FlatFileData( [ActionName] int NOT NULL, [DbName] varchar, [TableName] varchar, [BacthId] int, [StepId]int) --Read the Data from Test.txt into temp table #FlatFileDataSET @sql='BULK INSERT #FlatFileDataFROM ''C:\Test.txt''WITH (datafiletype = ''widechar'' --To specify the file is unicode use ''char'' for ansi files,firstrow=2--to skip the first row if the file has column names as first row,fieldterminator = ''\t''---to speficy it tab delimited,rowterminator = ''\n'')'EXEC (@sql)SELECT @Count = count(1) FROM #FlatFileData --> Boolean error at this line WHILE(@Count > 0) BEGIN SELECT @Action = ActionName , @DBName = DbName, @TableName=TableName, @BatchID = batchId, @StepID = StepId from #FlatFileData if @Action = 'Delete' BEGIN --> syntax '=' error at this line.. SET @executeSQL= 'delete from ' + @TableName exec (@executeSQL) END IF @action='UpdateStepRunCounter' Begin select @controlvalue = (select @controlvalue = attributevalue from importstepattribute where stepid=@Stepid and Batchid=@batchid and attrbiutename='controlvalue') update ImportStepRunCounter set CounterValue = @ControlValue where CounterName = 'ControlValue' AND BatchId = @BatchID AND StepId = @StepID AND RunId = (Select MAX(runId) from ImportStepRunCounter where Step ID = @StepId AND BatchID = @BatchId) End IF @action='UpdateMaxControlValue' Begin select @controlvalue = (select @controlvalue=attributevalue from importstepattribute where stepid=@Stepid and Batchid=@batchid and attrbiutename='controlvalue') update ImportStepRunCounter set CounterValue = @ControlValue where CounterName = 'ControlValue' AND BatchId = @BatchID AND StepId = @StepID AND RunId = (Select MAX(runId) from ImportStepRunCounter where Step ID = @StepId AND BatchID = @BatchId) End END--Drop temporary tablesDROP TABLE #FlatFileDataCommit TransactionEND TRYBEGIN CATCHIF @@TRANCOUNT >0Begin Rollback Tran EndIF object_id('tempdb..#FlatFileData') IS NOT NULLDROP TABLE #FlatFileData-- Raise an error with the details of the exception DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY() RAISERROR(@ErrMsg, @ErrSeverity, 1)With LOGEND CATCH |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|