I want to create an index for my SQL Table Column I have also asked a Question before here: https://stackoverflow.com/questions/17842488/index-similar-records-sql-server
I just need to know that I have created a Query that I want to copy my all data from my existing table to a new table! the query is to be executed using Java Platform!
Statement stat=con.createStatement();
ResultSet ss;
String s="Select * INTO log2 FROM log SELECT *, DENSE_RANK() OVER (ORDER BY ip) basescore from log";
ss=stat.executeQuery(s);
The problem is that it creates a table named log2 as a new table for me and a column basescore WITHOUT any values to be generated! I don't why it is not working with Java because I have tried it with SQL Server Query and it executes Successfully! Please can somebody help me please I will be thankful to him please
-
Is your query syntatically correct? Try to run the query on sql server first.Juned Ahsan– Juned Ahsan2013年07月25日 09:13:47 +00:00Commented Jul 25, 2013 at 9:13
-
Query doesn't seem correct. Those are two queries on one single line. Maybe this works from management studio, but in Java I think you should make two queries out of them or put a semicolumn in between.Pieter– Pieter2013年07月25日 09:15:44 +00:00Commented Jul 25, 2013 at 9:15
-
yes it is working fine with management studio so it seems like the query is correct enough but unable to done with it using Javauser2496503– user24965032013年07月25日 09:17:39 +00:00Commented Jul 25, 2013 at 9:17
1 Answer 1
If what you want is to create a new table log2 with the values from log plus the dense rank as basescorethe query should look like this:
SELECT *, DENSE_RANK() OVER (ORDER BY ip) basescore INTO log2 FROM log
If you only want unique rows you can add the DISTINCTkeyword after SELECT (and instead of using * you might want to specify the column names in the query).