Solved

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

Posted on 2011-03-17
2
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

628 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