473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

INSERT INTO EXCEPT doesn´t work

I have this statement:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO LlamadasRecompra (CodigoCompra, ClaveVive, Paciente, Status, Tel1, Tel2,
  2.  Cel, Presentacion, Dosis, Compras, Medico,
  3.  FechaUC, FechaCargaReceta, Receta)
  4. (SELECT COD_COMPRA AS CodigoCompra, CLAVE_V AS ClaveVive, PACIENTE AS Paciente, STATUS AS Status, TEL1 AS Tel1, TEL2 AS Tel2,
  5.  CEL AS Cel, PRESENTACION_UC AS Presentacion, DOSIS_DIARIA_VIVE AS Dosis, COMPRAS AS Compras, MEDICO AS Medico,
  6.  CONVERT(datetime, FECHA_UC, 103) AS FechaUC, CONVERT(datetime, FECHA_CARGA_RECETA, 103) AS FechaCargaReceta, RECETA AS Receta 
  7. FROM InfoParticipantes 
  8. EXCEPT SELECT CodigoCompra, ClaveVive, Paciente, Status, Tel1, Tel2,
  9.  Cel, Presentacion, Dosis, Compras, Medico,
  10.  FechaUC, FechaCargaReceta, Receta FROM LlamadasRecompra)
  11.  
When I run the SELECT-EXCEPT SELECT part it runs perfectly returning more than 3000 registers, but when I run it all it inserts nothing to my table. Any idea why?

Thanks for your help.
Aug 19 '11 #1

✓ answered by ck9663

If you run it once and the record gets inserted, the second time you run the same query with the same values, EXCEPT will no longer return anything since you just inserted it. Anyway, if you're still having issue, try to dump it into another table and insert that table. I advice you create a unique index on your target table to avoid duplicate.


Happy Coding!!!


~~ CK

4 6248
ck9663
2,878 Expert 2GB
Are there any error? Try to isolate the issue. Do an SELECT...INTO... then check the output table. If it's still happening, use CTE for your select then insert it to your target table.


Happy Coding!!!


~~ CK
Aug 20 '11 #2
Thanks for your help CK. The code doesn't shows any error, it just doesn't insert any row. As I said before, if I run the SELECT-EXCEPT SELECT part alone it returns a table with all the data, but all together it just doesn't insert anything. A thing I forgot to say is that if the destination table is empty it inserts all the rows from the other table, it just doesn't work if there is already data in the table. The destination tabale has no primary key and there is no data type conflict.
Aug 22 '11 #3
ck9663
2,878 Expert 2GB
If you run it once and the record gets inserted, the second time you run the same query with the same values, EXCEPT will no longer return anything since you just inserted it. Anyway, if you're still having issue, try to dump it into another table and insert that table. I advice you create a unique index on your target table to avoid duplicate.


Happy Coding!!!


~~ CK
Aug 22 '11 #4
Thank you CK, creating an unique index worked perfectly. I was trying to add new items, not the ones I already inserted, and the problem was solved with the index.
Aug 22 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: OldGuy | last post by:
Hi All Sendmail 8.12.11 php 4.3.9 Sendmail is installed and works properly. php is NOT in safemode from the command line; mail user@domain.com < testmsg works fine.
1
by: Jan Stenberg | last post by:
I have a situation where I open a database connection in main script. Then I start a transaction, have some queries, include an another php file within some queries and then commiting queries in...
3
by: Eric Gibson | last post by:
I could have sworn this would be a FAQ, but it doesn't appear to be in there. You must get this all the time, or I'm just totally doing something wrong. Math with int's and floats appears to...
16
by: Luca | last post by:
About one month ago I have inserted in my web site a clickcounter who controls the access to almost every link, but this script who changed the path in every link so the search engines couldn't...
7
by: J. Hall | last post by:
Hi dudes, Got a simple webpage, with three numeric text input boxes, the idea being that the user is asked to insert percentages of their business around the world... UK, Europe, Other ...
3
by: milkyway | last post by:
Hello, I am working with an old Java Script code and have found the following but after putting in alerts I have found that insertRow doesn't work. What is the problem? TIA function...
4
by: Jacinle Young | last post by:
Hi all, I have written the SQL but it doesn't work db2 "select acode from t1 where (acode) not in (select eid from t2 where iid ='0') and iid ='0'" select nothing but the following works
11
by: C. Sengstock | last post by:
Hi, i want to save the keywords of an ini file in a struct, together with a fpos_t. I think i´m right with the concept, but the access through fsetpos() doesn´t work. The position is always wrong...
0
by: zhengmao | last post by:
I have one store procedure, which works fine in SQL Analyzer when I test it out, but doesn't work when I call it in web application. the problem is it doesn't insert last line, and the problem is...
0
by: Ely Raeds | last post by:
Hey When I run my program with a break on txtnaam.text my program works the way it should work. When I run it by pressing F5 it doesn't work like it should. My Listbox doesn't show the data when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.