Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Store procedure insert into function

Author  Topic 

eddietwal
Starting Member

5 Posts

Posted - 2014-08-10 : 01:26:32
I have 2 tables

First Table is CUSTOMERS with the columns (CustomerId, CustomerName) Second Table is LICENSES with the columns (LicenseId, Customer) The column customer from the second table is the CustomerId from the First table

I wanted to create a store procedure that insert values into table 2

Insert into Licenses (Customer) Values( Same As CustomerId)
HOW i can get this data from the other table?
Thanks For the Help in Advance

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-10 : 08:03:15
Use a select clause
Go to Top of Page

eddietwal
Starting Member

5 Posts

Posted - 2014-08-10 : 11:31:46
I don't think thats what I need here.
Go to Top of Page

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-10 : 18:00:26
c
Go to Top of Page

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-10 : 18:05:05
c
Go to Top of Page

b8538230
Starting Member

16 Posts

Posted - 2014-08-10 : 18:38:06
quote:
Originally posted by eddietwal

I don't think thats what I need here.



e.g.

insert into sometable(col1, col2, col2)
select col1, col2, col3
from someothertable

Go to Top of Page

eddietwal
Starting Member

5 Posts

Posted - 2014-08-10 : 21:03:54
Chris,
nice idea but it only works one time because the second time you run the sp you get an error (Subquery returned more than 1 value. )
Go to Top of Page

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-10 : 21:11:43
c
Go to Top of Page

eddietwal
Starting Member

5 Posts

Posted - 2014-08-10 : 21:27:47
I'm sure its going to be a simple solution. I will find out when I get to work tomorrow morning. I will ask one of the seniors. I will post back the solution later on tomorrow.
Go to Top of Page

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-10 : 22:08:46
c
Go to Top of Page

eddietwal
Starting Member

5 Posts

Posted - 2014-08-10 : 23:35:26
I will try this now. By the way Customer
from the Licenses table is the CustomerId from the Customers table just FYI

Meaning that you can't insert any values in the customer field. It takes its data from the cutomerId column

INSERT INTO #LICENSES (LICENSEID, CUSTOMER)
VALUES (1,'WAL') you can't fill the customer column it takes it from the other table.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-11 : 07:40:17
quote:
Originally posted by eddietwal

I will try this now. By the way Customer
from the Licenses table is the CustomerId from the Customers table just FYI

Meaning that you can't insert any values in the customer field. It takes its data from the cutomerId column




but Licenses.Customer is a varchar and Customer.CustomerId is an int. How can they be the same?

Go to Top of Page
   

- Advertisement -