SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Insert into existing table but for each group?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tech_1
Posting Yak Master

105 Posts

Posted - 01/27/2013 :  18:28:07  Show Profile  Reply with Quote
I have a large table with existing data.
The joining key/column is "UserID" (varchar)
I want to insert a record in this table but for each UserID found in the table

how can I do this?

There are multiple single userID's in there, each with a different column value which is linked to another table (think of it as a joining reference table for settings for each user)

any ideas?

James K
Flowing Fount of Yak Knowledge

3636 Posts

Posted - 01/27/2013 :  18:47:46  Show Profile  Reply with Quote
I did not quite follow what you meant by groups - if the data for a given userid already exists, don't you want to do an update rather than insert duplicate rows for the same userid? Can you post the schema for the two (or more tables) that are involved along with some sample data?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/28/2013 :  00:03:52  Show Profile  Reply with Quote
Sounds like OP wants to replicate some data for each of existing users but add only once per user. Seems like currently table is having multiple records per user.

If thats the case, it should be something like

INSERT INTO YourTable (UserID,.. other columns)
SELECT UserID,
value1,value2,..
FROm (SELECT DISTINCT USerID FROM YourTable)t


if this was not your question then please post some sample data as James suggested as we cant make out much from your current explanation.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

srimami
Posting Yak Master

160 Posts

Posted - 01/29/2013 :  08:12:17  Show Profile  Reply with Quote
If I am not wrong, you wanted to lookup for userid's existing on other table in your join condition and for each userid it matched, you wanted to insert values. Let us know in detail.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000