Reputation: 11
I need to connect to sql server 2008 and 2012 version with spring jdbc template.
In database, we have column with spaces, I tried with wrapping column which has spaces with [], ""
, but no use. The following error occurred, when I use a query
SELECT Mon, CC Flag FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Msisdn)AS RowNum FROM ME_PREPAID) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN 2 AND 100
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'CC'.
Please note that, there is column as CC Flag
How can I solve this issue?
Upvotes: 0
Views: 726
Reputation: 11
Finally, I found solution for this question. I used like this [column name]
. It works fine. I already tried like this. But there was a mistake in programming while matching the column names with a list. I used a array list with the values [Mon],[CC Flag]
.
mylist.add="[Mon]"; mylist.add="[CC Flag]";
Then I passed this list to the query. When I match the columns name with the list, there was a mistake. The following one is the correct answer.
SELECT [Mon], [CC Flag] FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Msisdn)AS RowNum FROM ME_PREPAID) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN 2 AND 100
Upvotes: 0
Reputation: 13066
You can try this SQL String:
String sql = "SELECT Mon, \"CC Flag\" FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Msisdn)AS RowNum FROM ME_PREPAID) AS MyDerivedTable WHERE MyDerivedTable.RowNum BETWEEN 2 AND 100";
Upvotes: 1