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
 updating a field with info from other fields

Author  Topic 

davemino
Starting Member

1 Post

Posted - 2008-05-08 : 11:47:09
I am trying to make a field that has info from othe fields

Table = Page0
Fields = LName, FName, SS

I want a new field (Folder) to be all three fields.. for example
LName= Smith
FName= John
SS= 1234

I want to update Folder = Smith_John_1234

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 11:51:50
Update Page0
SET Folder = ISNULL(LName+'_','')+ ISNULL(FName + '_','') + ISNULL(CAST(SS AS varchar(5)),'')
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-08 : 11:53:52
Or one of these 2?...

-- Structure and Data
create table Page0 (LName varchar(10), FName varchar(10), SS varchar(10))
insert Page0
select 'Smith', 'John', '1234'

-- Example using select
select *, LName + '_' + FName + '_' + SS as Folder from Page0

-- Example computed column
alter table Page0 add Folder as LName + '_' + FName + '_' + SS
select * from Page0


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 12:00:13
quote:
Originally posted by RyanRandall

Or one of these 2?...

-- Structure and Data
create table Page0 (LName varchar(10), FName varchar(10), SS varchar(10))
insert Page0
select 'Smith', 'John', '1234'

-- Example using select
select *, LName + '_' + FName + '_' + SS as Folder from Page0

-- Example computed column
alter table Page0 add Folder as LName + '_' + FName + '_' + SS
select * from Page0


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.


I think we need to check for NULL values in all of fields as it might cause result to be returned as NULL.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-08 : 12:07:01
How do you know returning NULL isn't the requirement?

I considered adding that detail, but figured we needed to pin down what was meant a bit first...


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 12:22:03
quote:
Originally posted by RyanRandall

How do you know returning NULL isn't the requirement?

I considered adding that detail, but figured we needed to pin down what was meant a bit first...


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.


Ok . Just thought of specifying it just in case OP preffered non null values
Go to Top of Page
   

- Advertisement -