[dba-SQLServer] SPROC Help SELECT and INSERT.

Darryl Collins Darryl.Collins at coles.com.au
Sat Sep 27 19:28:50 CDT 2008


Hi guys and gals,

A bit of advice if you don't mind. Trying to write a SPROC and know this should be easy and I think I am making it way too complicated.

I have data in one table and want to copy and insert into another table (identical fields pretty much).  So for each example

tblSource
'-------------------
SourceKeyID (PK)
Alpha
Beta
Gamma
FYP
Prog

so: SQL would be

SELECT * FROM tblSource
WHERE FYP = @FYP AND Prog = @Prog

or maybe

SELECT
SourceKeyID,
Alpha,
Beta,
Gamma,
FYP,
Prog
FROM tblSource
WHERE FYP = @FYP AND Prog = @Prog

Then I want to insert it in to the tblTarget table.

tblTarget
'-------------------
TargetKeyID ' Auto generated
FYP_Imported ' Needs to be written as a variable (eg 75)
SourceKeyID (FK) ' The following all come from the source table
Alpha
Beta
Gamma
FYP
Prog

Something like

INSERT INTO tblTarget
FYP_Imported = @FYP_imported
SourceKeyID,
Alpha,
Beta,
Gamma,
FYP,
Prog

.

Anyway, I can't seem to get it to work so I am clearly fouling something up
*sigh* any advice?

cheers
Darryl.




-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com]On Behalf Of Arthur
Fuller
Sent: Saturday, 27 September 2008 3:09 AM
To: Discussion concerning MS SQL Server
Subject: [dba-SQLServer] Automatic drop of everything related to a table


When you drop a table, do all related objects automatically get dropped as
well? By "related objects" I don't mean related tables, but rather
constraints, triggers, indexes and so on. Does dropping a table
automatically kill all this stuff, or do remnants persist, and if the
latter, is there some systematic way of killing all the remnants when I kill
the table?

You might wonder why I want to do this. I'd tell you but then I'd have to
kill you. (It's Friday. so I may let you live until Monday.)

A.
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com


This email and any attachments may contain privileged and confidential information
and are intended for the named addressee only. If you have received this e-mail in
error, please notify the sender and delete this e-mail immediately. Any
confidentiality, privilege or copyright is not waived or lost because this e-mail
has been sent to you in error. It is your responsibility to check this e-mail and
any attachments for viruses.  No warranty is made that this material is free from
computer virus or any other defect or error.  Any loss/damage incurred by using this
material is not the sender's responsibility.  The sender's entire liability will be
limited to resupplying the material.





More information about the dba-SQLServer mailing list