BATCH FILE:
ECHO OFF
SET /P colu= Enter column name:
SET /P sn= Enter ID (split by commas):
rem Grab filenames in an array
set n=0
for %%a in (%SN%) do (
set /A n+=1
set "id[!n!]=%%~a"
)
rem For example, to process the filenames:
for /L %%i in (1,1,%n%) do (
echo %%i- !id[%%i]!
)
sqlcmd -U USER-P PASSW -S SERVER -d DB -i sqlFILE.sql -o LOGS.txt -v delete=colu d_id=snode
I want to delete several ids from the database. This batch file asks the user what they want to be deleted and it is suppose to put the entered values in an array.
These entered values are entered into this SQL script:
declare @columnName nvarchar(255)
declare @intValue int
set @columnName = '$(colu)' --COLUMN NAME WHERE VALUE IS LOCATED
set @intValue = '$(sn)' --VALUE TO BE DELETED
declare @DeleteValue varchar(10)
set @DeleteValue = convert(varchar(10), @intValue)
declare @sql nvarchar(max) = ''
select @sql = @sql + 'delete ' + object_name(c.object_id) + ' where ' + @columnName + ' IN ' + @DeleteValue + ';'
from sys.columns c
where c.name = @columnName
select @sql
exec sp_executesql @sql
The problem is that the program is still looking at the values entered as one whole value and not separate values.