0

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

asked Jul 25, 2013 at 9:10
3
  • Is your query syntatically correct? Try to run the query on sql server first. Commented 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. Commented 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 Java Commented Jul 25, 2013 at 9:17

1 Answer 1

2

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).

answered Jul 25, 2013 at 9:45
Sign up to request clarification or add additional context in comments.

1 Comment

I think I am new to SQL and People like you always help others so thanks to you !!! hats off Sir ! so nice of you!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.