I've created a foreach loop that loops through Excel files the sheets within them. Based on the name of the sheet, one of a number of data flow tasks is executed.
This is implemented by an execute SQL task that validates a variable against values in a table, and returns a value based on some conditions.
For some reason, it is working perfectly when the sheet name doesn't have any spaces (e.g. MyTab) however, when there is a space (e.g. My Tab), it does not match correctly.
I've tried evaluating the sheet name against the following values in the DB table.
- My Tab$
- 'My Tab$'
- 'My Tab'$
- {'My Tab$'}
- [My Tab$]
- ['My Tab$']
- "My Tab$"
- My Tab
- MyTab$
- (My Tab$)
- ''My Tab$''
- [''My Tab$'']
- My$Tab$
However none of these will evaluate against the sheet name "My Tab"
The SQL I'm using to evaluate the variable is:
DECLARE @SheetName VARCHAR(100)
SET @SheetName = 'Tab1$'
IF EXISTS (SELECT 1
FROM [dbo].[xx]
WHERE sheetname = @SheetName)
-- The variable evaluates against the values in the sheetname column
BEGIN
SELECT 1 AS SheetExistsFlg
END
ELSE IF EXISTS (SELECT 1
FROM [dbo].[xx]
WHERE 'Tab 2$' = @SheetName)
BEGIN
SELECT 2 AS SheetExistsFlg
END
ELSE
BEGIN
SELECT 0 AS SheetExistsFlg
END
Any ideas?