Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

914 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

18 Experts available now in Live!

Get 1:1 Help Now