Skip to content
Advertisement

Stored procedure to unpivot

I have a table with these columns:

Where fields from 01 to 50 are dates. I need to have a table like this:

Where title code should be the column name from 01 to 50, data should be the value of that column in mytable

I did this stored procedure by looking in older questions:

but I’m getting a syntax error near '.01'. Could someone help me please?

Advertisement

Answer

The problem is with the column names: since they start with a digit, you need to quote the identifiers – in SQL Server, you need to use square brackets. You can take care of that this in the first query.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement