Results 1 to 2 of 2

Thread: Now A really complex query...

  1. #1

    Thread Starter
    Hyperactive Member Daskalos's Avatar
    Join Date
    Jun 2002
    Location
    Just behind YOU...
    Posts
    364

    Now A really complex query...

    well.. thank to szlamany, i saw that my last post was quite simple...
    and my problem a bit more complicated..
    i'll try to tell exactly what i need
    i have a table called Foto, one called Noticia, Area and one called Unidade.

    i need to make a copy of everything associated with idUnidade = 17
    but in another idUnidade (30)..

    so if i have one Row in Noticia with idNoticia = 30 and the idUnidade from that idArea is 17, than i need it to be copied AND the data from table Foto that have the idNoticia = 30, will be copied and idNoticia will be updated to the idNoticia of the new data...



    i don't know it can be done only with SQL Server.. so, if don't, could someone suggest a program to help me!?

    thanks in advance...
    Attached Images Attached Images  
    Last edited by Daskalos; Apr 11th, 2005 at 05:06 PM. Reason: forgot the picture...
    [vbcode]Dim Daskalos As NewBie
    If My.english = Wrong Then
    Forgive My.Poor.English
    End If[/vbcode]
    Ða§kalø§
    ICQ#: 36146307
    Current ICQ status:
    More ways to contact me

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Now A really complex query...

    First I would suggest using a STORED PROCEDURE to create a table variable - load it with the data you want and then INSERT from it.

    Keep in mind that you can say something like this in SQL.

    Code:
    Insert into Area
       Select idArea,Nome,30,layoutChamada,quantidade,layout From Area
           Where idUniDade=17
    This will create new rows in Area - with the idUniDade of 30, but from a population of data that has the value 17 - basically copying 17 to 30.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width