Saturday, February 25, 2012

Chaging SSN Format

This is a repost due to know response:
If I use this formula:
SELECT LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' + RIGHT(ssnum, 4)
as SSN, Clients.First_Name + ' ' + Clients.Last_Name
FROM Clients
It recodes the SSN as I need it. How do I get this result to the UPDATE
function inside the main db?
Possibly:
Update Clients
Set LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' + RIGHT(ssnum, 4)
I tried that code but get a syntax error. Any ideas?> Possibly:
> Update Clients
> Set LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' + RIGHT(ssnum,
> 4)
Try:
UPDATE dbo.Clients
SET ssnum = LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' +
RIGHT(ssnum, 4)
However, I generally suggest storing unformatted data and instead format
strings in the application/report during presentation
Hope this helps.
Dan Guzman
SQL Server MVP
"JOHN HARRIS" <harris1113@.fake.com> wrote in message
news:E9C89F84-1950-4670-A852-49033092BD83@.microsoft.com...
> This is a repost due to know response:
> If I use this formula:
> SELECT LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' + RIGHT(ssnum,
> 4)
> as SSN, Clients.First_Name + ' ' + Clients.Last_Name
> FROM Clients
> It recodes the SSN as I need it. How do I get this result to the UPDATE
> function inside the main db?
> Possibly:
> Update Clients
> Set LEFT(ssnum, 3) + '-' + SUBSTRING(ssnum, 4, 2) + '-' + RIGHT(ssnum,
> 4)
> I tried that code but get a syntax error. Any ideas?

No comments:

Post a Comment