Link to home
Start Free TrialLog in
Avatar of shwelopo
shwelopo

asked on

SQL query

I'm trying to list the numbers between 515000 and 516000 to insert into an empty table (nvarchar type)
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Please use this..

Do not worry about the conversion, DB will implicitly convert the INT values to NVARCHAR.

IF the table is already there..

INSERT INTO yourNewTable(Column1,Column2....etc)
SELECT Column1,Column2....etc
FROM yourTable
WHERE NumberCol >= 515000 and NumberCol<= 516000


IF the table is NOT already created

SELECT Column1,Column2....etc
INTO yourNewTable
FROM yourTable
WHERE NumberCol >= 515000 and NumberCol<= 516000
FOR ORACLE

IF the table is already there..

INSERT INTO yourNewTable(Column1,Column2....etc)
SELECT Column1,Column2....etc
FROM yourTable
WHERE NumberCol >= 515000 and NumberCol<= 516000;

IF the table is NOT already created

CREATE TABLE yourNewTable
AS
(
      SELECT Column1,Column2....etc FROM yourTable
      WHERE NumberCol >= 515000 and NumberCol<= 516000
);
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

DO NOT use RECURSION

And the reason for that is...?


»bp
>>And the reason for that is...?
It slows down the things..we need to use SET based approach in all RDBMS's as they are naturally fast in nature as you play with the entire DATASET.. ..But for one time activity anything will do as i mentioned in my last post.
For generating a sequence of 1000 values the RECURSIVE approach works just as fast and I personally find the code easier to write and understand.


»bp
Yes you can use..its perfectly alright but it is not the preferred method...for DB engine.