Solved

how to make nested select inside insert into to copy one table to another?

Posted on 2011-03-17
2
221 Views
Last Modified: 2012-05-11
hi,

I wanna copy values from one table to another after applying some condition,  so I put nested select in my insert into statement, but this not working !

here is my try:

 
insert into FilteredNumbers (MobileNumber, IntrMobileNumber) values (

select replace(id_txt, '+1', ''), id_txt from dbo.no_generate where id_txt not like '%000%'
and id_txt not like '%111%'
and id_txt not like '%222%'
and id_txt not like '%333%'
and id_txt not like '%444%'
and id_txt not like '%555%'
and id_txt not like '%666%'
and id_txt not like '%777%'
and id_txt not like '%888%'
and id_txt not like '%999%'

and id_txt not like '%012%'
and id_txt not like '%123%'
and id_txt not like '%234%'
and id_txt not like '%345%'
and id_txt not like '%456%'
and id_txt not like '%567%'
and id_txt not like '%678%'
and id_txt not like '%789%'
and id_txt not like '%890%'
and SUBSTRING ( id_txt , 8 , 3 ) <> SUBSTRING ( id_txt , 11 , 3 )
)

Open in new window

0
Comment
Question by:njgroup
2 Comments
 

Author Comment

by:njgroup
ID: 35158844
I got his error:

Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near ')'.
0
 
LVL 4

Accepted Solution

by:
qasim_md earned 500 total points
ID: 35158858
Try this::::

insert into FilteredNumbers (MobileNumber, IntrMobileNumber)
select replace(id_txt, '+1', ''), id_txt from dbo.no_generate where id_txt not like '%000%'
and id_txt not like '%111%'
and id_txt not like '%222%'
and id_txt not like '%333%'
and id_txt not like '%444%'
and id_txt not like '%555%'
and id_txt not like '%666%'
and id_txt not like '%777%'
and id_txt not like '%888%'
and id_txt not like '%999%'

and id_txt not like '%012%'
and id_txt not like '%123%'
and id_txt not like '%234%'
and id_txt not like '%345%'
and id_txt not like '%456%'
and id_txt not like '%567%'
and id_txt not like '%678%'
and id_txt not like '%789%'
and id_txt not like '%890%'
and SUBSTRING ( id_txt , 8 , 3 ) <> SUBSTRING ( id_txt , 11 , 3 )
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trying to get a Linked Server to Oracle DB working 21 76
sql query help 15 50
SQL Sum of items in two tables not equal. 5 42
SQL Server Express or Standard? 5 18
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question