Results 1 to 10 of 10

Thread: Anybody into SQL?

  1. #1
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307

    Anybody into SQL?

    Hi all,

    long shot, but I'm looking to solve a problem I have, I need a sql-statement which is like this:

    insert into prijslijst (product,retail_prijs,nl_gelijk,[<_Exp_1],Exp_1,Exp_1_aantal,Exp_2,Exp_2_aantal,Exp_3,Exp3_ aantal,Oudh,Topcons,Afinor,Beaver, Argend,[M-east],Samengesteld_uit,Hoofdgroep,interne_code,NS,code) values ('', '', '', '', '', '', '', '','', '', '', '', '', '', '', '', '', '/1/', (select max(interne_code) from prijslijst), FALSE,'')

    but actually works!

    anybody... please...??? I'm going bunkers over this, there must be a way to do something like this, I just can't figure out how....

    trhanx!
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  2. #2
    Maximum Bitrate Raas's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    626
    what kind of db is it ??

    what do you want to do ??

    If the info is not to critical send me a copy of the table and a description of what you want to do, and then I will see if I can help..


    Greetz.

    Raas
    (mark.raassens@12move.nl)
    Raas - The Netherlands
    ME: VIA epia m10000, lilliput 7', opus 150w, 80gb<br>
    GF: IBM Thinkpad 380, ext. 3.5 80gb, 40x4, PB-IR

  3. #3
    FLAC
    Join Date
    Aug 1999
    Location
    Upper Marlboro, MD 20772
    Posts
    1,311
    if this is mysql, then you have ur work cut out for you.
    abcd-1
    Author of CobraI,II,III and now CobraIV.
    You can contact me on AOL instant messenger....nick is cenwesi or cenwesi3

  4. #4
    Maximum Bitrate
    Join Date
    Mar 2001
    Location
    Cincinnati, OH USA
    Posts
    694
    What error message does it give you? I believe one of your variables (code) is restricted and can't be used, try changing it. If it is an Access database try running it within Access, it should help you out. Also is it for the web or just a database for your use? One resource I commonly use for web database problems is http://www.aspmessageboard.com (try searching with the error message).
    http://www.mp3car.com/usersites/Maveric/ M.A.V.I.C. System
    Asus MB, PII 266, 192 MB Ram, 6.8" LCD, 6 Disk CD-ROM, 21 Gig HD, All-in-Wonder Video w/ TV Tuner, Irman, Windows ME, Winamp, Cobra III -- All in a custom acrylic case.

    http://www.mp3car.com/usersites/listings/ MP3car Listings - Please add to it! :)

  5. #5
    Variable Bitrate
    Join Date
    Nov 1999
    Location
    Ishoej, Denmark
    Posts
    310
    This advide is based on microsoft sql server, and may not work on other types!

    Appart from (code) could be a reserved word, the < character may cause it troubles as well (even if its in [] )

    One other thing may cause you a problem. If the interne_code doesnt allow null and you are trying to insert the firstvalue it will most likely fail.
    If this is indeed your problem use a command like ( isnull). meaning it would look like this


    insert into prijslijst (product,retail_prijs,nl_gelijk,[< _Exp_1],Exp_1,Exp_1_aantal,Exp_2,Exp_2_aantal,Exp_
    3,Exp3_aantal,Oudh,Topcons,Afinor,Beaver, Argend,[M- east],Samengesteld_uit,Hoofdgroep,interne_code,NS,
    code) values ('', '', '', '', '', '', '', '','', '', '', '', '', '', '', '', '', '/1/', isnull((select max(interne_code) from prijslijst),''), FALSE,'')


    But as the others have stated we need more info to really help you out. especially the COMPLETE error you get, and if possible the table construction info (fieldnames, datatypes, properties(allowsnull, defaultvalue etc))

    Appart from that we would like to know what system you are trying to run it on ie: microsoft, oracle, sybase, mysql etc. We may need that info because every sql server type, has its own quirks and weird little details that can trip you up.

    Good luck

  6. #6
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    the error I'm getting is -3058 undescribed error
    nah problem is the select statement in the insert statement, if I remove this by a "normal" integer value all goes well.
    It's just that I really didn't wanna use 2 queries. but hey if that is the only option......
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  7. #7
    FLAC
    Join Date
    Apr 2001
    Location
    Here, There, Everywhere
    Posts
    1,436
    yeah some DB's dont support sub-queries within INSERT/UPDATE statements.... MS SQL is one of em.....

    also is that MAX() function returning an integer from the specfied DB table? IF you have no records in that table it will return NULL which will trip it up.....

    you can use the COALESCE function with MS SQL which will replace a occourance of NULL with a specfied character.....


    thus


    SELECT COALESCE(MAX(foobar),-1) FROM tablename

    will return -1 in an instanace where MAX() returns NULL....
    Project - GAME OVER :(

  8. #8
    Variable Bitrate
    Join Date
    Nov 1999
    Location
    Ishoej, Denmark
    Posts
    310
    magnetik is partially right It doesnt allow you to do sub queries like that but it does however allow you to do this little trick

    (This is frmo one of my databases convert for own needs)

    insert into aisle (name, description) (select max(aisleid),'test' from aisle)

    Notice that the "value" is gone and that only the select is left, thus allowing you to insert your complete select

    Hope this one fixes the problem, otherwise we do need to know the type of server (if you dont want to say your are using a full blown mssql server(is anyone listening ?). then say your are using the msde (microsoft database engine), which is for free (under certain circumstances, and will do almost all the things an ordinary ms sql server will do.

    Please let us know if you get your problem solved, since i believe that most of us are more than willing to help you out.

  9. #9
    Variable Bitrate
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    307
    Darkwingduck your the best!

    Ah never thought of using a "fake" multi-row insert!!!

    Thank you very much.... this really helps me I've been coming across this problem pretty often, now I have a way f solving it!!!
    If at first you don't succeed.........
    destroy all evidence you tried

    for info on t6369c LCD or Presslab's powersupply check:
    http://www.namms.tk <=updated!!

  10. #10
    Variable Bitrate
    Join Date
    Nov 1999
    Location
    Ishoej, Denmark
    Posts
    310
    Glad to help and glad to se that it worked

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •