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
 General SQL Server Forums
 New to SQL Server Programming
 Input values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jfm
Posting Yak Master

145 Posts

Posted - 05/02/2013 :  06:32:35  Show Profile  Reply with Quote
Hi there,

Im working with two different tables:

t_a
t_b

t_a has some rows in col_1 with '*' as a value
t_b has the correct values for the rows ('*') in t_a, col_1

I need to copy the values of t_b in t_a when t_a, col_1 has '*' as a value

Any tip?

Thanks

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/02/2013 :  07:04:08  Show Profile  Reply with Quote

update a
set a.col_1 = b.col_1
from t_a a
inner join t_b b
on b.relatedcolumn = a.relatedcol
where a.col_1='*'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 05/02/2013 07:05:14
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 05/02/2013 :  07:28:51  Show Profile  Reply with Quote
Hi visakh16,

thanks for your help.

I have an error msg:

msg 4104, level 16, state 1, line 1
The multi-part identifier 'a.col_1' could not be bound.

I do have that column in that file. I dont understand what's wrong..

Any idea?

Thank you



quote:
Originally posted by visakh16


update a
set a.col_1 = b.col_1
from t_a a
inner join t_b b
on b.relatedcolumn = a.relatedcol
where a.col_1='*'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/02/2013 :  07:32:44  Show Profile  Reply with Quote
file? do you mean t_a is a file and not a table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 05/02/2013 :  08:42:59  Show Profile  Reply with Quote
Sorry,

Yes, in that table not file.

quote:
Originally posted by visakh16

file? do you mean t_a is a file and not a table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 05/02/2013 :  08:46:21  Show Profile  Reply with Quote
some where you are misusing column name... can you post your complete query once...?

--
Chandu
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 05/02/2013 :  09:03:11  Show Profile  Reply with Quote
Sure,

This is my query:

update S
set s.PP = b.PP
from S as s
inner join pp_wr as b
on s.I_CN = b.I_CN
and s.S_N = b.S_N
and s.IS = b.IS
and s.I_D = I_Date
where s.PP = '*'





quote:
Originally posted by bandi

some where you are misusing column name... can you post your complete query once...?

--
Chandu

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 05/02/2013 :  09:19:44  Show Profile  Reply with Quote
try like this... If not, post us the columns of both tables separatley
update a1
set a1.PP = b.PP
from S as a1
inner join pp_wr as b
on a1.I_CN = b.I_CN
and a1.S_N = b.S_N
and a1.IS = b.IS
and a1.I_D = I_Date
where a1.PP = '*'


--
Chandu
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 05/02/2013 :  09:44:53  Show Profile  Reply with Quote
chandu,

I might be wrong but I think the query is the same as mine..

thanks

0
quote:
Originally posted by bandi

try like this... If not, post us the columns of both tables separatley
update a1
set a1.PP = b.PP
from S as a1
inner join pp_wr as b
on a1.I_CN = b.I_CN
and a1.S_N = b.S_N
and a1.IS = b.IS
and a1.I_D = I_Date
where a1.PP = '*'


--
Chandu

Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1054 Posts

Posted - 05/02/2013 :  14:35:06  Show Profile  Reply with Quote
quote:
Originally posted by jfm

Sure,

This is my query:

update S
set s.PP = b.PP
from S as s
inner join pp_wr as b
on s.I_CN = b.I_CN
and s.S_N = b.S_N
and s.IS = b.IS
and s.I_D = I_Date
where s.PP = '*'





quote:
Originally posted by bandi

some where you are misusing column name... can you post your complete query once...?

--
Chandu





Are you sure you're getting the specified error message by executing this query??? I think you should not be getting it. As I don't see a.col_1 used anywhere in this query


Cheers
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52323 Posts

Posted - 05/03/2013 :  00:34:01  Show Profile  Reply with Quote
quote:
Originally posted by jfm

Sure,

This is my query:

update S
set s.PP = b.PP
from S as s
inner join pp_wr as b
on s.I_CN = b.I_CN
and s.S_N = b.S_N
and s.IS = b.IS
and s.I_D = I_Date
where s.PP = '*'





quote:
Originally posted by bandi

some where you are misusing column name... can you post your complete query once...?

--
Chandu




check if all the columns specified are available in the corresponding tables.
You can use INFORMATION_SCHEMA.COLUMNS view for that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.08 seconds. Powered By: Snitz Forums 2000