Solved

SQL Cross Join / Stored Proc

Posted on 2009-07-01
1
387 Views
Last Modified: 2012-05-07
I want to create a stored procedure that will take in a year, look up "active" rows in a "Code Table" and insert it into another table (Table B).  For instance:

Year: 2009

Code Table
ID - several other columns - Status
1 - ... - Active
2 - ... - Inactive
3 - ... - Active

Table B
Year - ID
2009 - 1
2009 - 3
0
Comment
Question by:mmeisel
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24757734
this should do:
create procedure yourproc @year int
as
  insert into table_b ( [year], ID )
   select @year, ID 
     from code_table

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

713 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