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
 Input values

Author  Topic 

jfm
Posting Yak Master

145 Posts

Posted - 2013-05-02 : 06:32:35
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

52326 Posts

Posted - 2013-05-02 : 07:04:08
[code]
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='*'
[/code]

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

jfm
Posting Yak Master

145 Posts

Posted - 2013-05-02 : 07:28:51
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

52326 Posts

Posted - 2013-05-02 : 07:32:44
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 - 2013-05-02 : 08:42:59
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-02 : 08:46:21
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 - 2013-05-02 : 09:03:11
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-05-02 : 09:19:44
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 - 2013-05-02 : 09:44:53
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
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-02 : 14:35:06
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

52326 Posts

Posted - 2013-05-03 : 00:34:01
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
   

- Advertisement -