Solved

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

Posted on 2011-03-17
2
215 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now