SQL_Query Error

Hi
I am trying to read data from excel using DB activities and need to extract data except one column.

Please help me in fixing the issue with the below code
“SELECT * FROM [SheetName$] WHERE ColumnName <> ‘Customer’”

Thanks in Advance

Hi @km81

SELECT
Column1,
Column2,
Column4,
Column5
FROM [Table Name]

Cheers…!

Hi @Dilli_Reddy

I have more that 250 columns in which only one column i need to exclude.

Can you pls suggest any other approach??

@km81

SELECT col1, col2, col3, col4, col5, col6, col7, col8, col9
FROM sample_table;

Hi @km81

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'YourSheetName$'
AND COLUMN_NAME <> 'ColumnToExclude'

In this query:

  • INFORMATION_SCHEMA.COLUMNS is a system table that stores information about columns in your Excel sheet.
  • TABLE_NAME = 'YourSheetName specifies the sheet you’re working with. Replace 'YourSheetName with the name of your Excel sheet.
  • COLUMN_NAME <> 'ColumnToExclude' excludes the specific column you want to exclude. Replace 'ColumnToExclude' with the actual column name you want to exclude.

This query retrieves the names of all columns except the one you want to exclude dynamically.specifies the sheet you're working with. Replace DISCOURSE_PLACEHOLDER_3` with the name of your Excel sheet.

Hope it helps!!

2 Likes

Hi @km81

Try this

SELECT Column1, Column2, Column3
FROM [SheetName$]
WHERE ColumnName <> 'Customer'

Hope this helps!!

2 Likes

@km81

Try this

Select * from Tablename

It gives output as datatable

Later use filter datatable activity to remove the required column

Cheers…!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.