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
 Cast/Convert numeric field to numeric text field

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-09-30 : 17:07:02
I have two tables with columns that have a numeric field, and I need to convert them to a numeric text field:

FAFSA11=
SSN(char(9),null)

ISIR11=
OriginalSSN(char(9),null)

I have a field that is numeric Text field named the following:
FAFSA11=
SSN(char(9),null)

ISIR11=
OriginalSSN(char(9),null)

I'm having a tough time with the syntax for the Convert

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

Could someone help me with this please.

Sachin.Nand

2937 Posts

Posted - 2010-10-01 : 01:56:42
[code]
declare @num numeric(10,2)
set @num=9.05
select convert(varchar(5),@num)
[/code]

PBUH

Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-10-01 : 08:44:07
Thank you!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-10-05 : 06:45:01
This type of formation should be done in front end application

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2010-10-06 : 09:24:39
select distinct
stud.ssn as systud_ssn,
fafsa.ssn as fafsa_ss,
isir.originalssn as isir_ssn
from
dbo.systudent as stud left outer join
dbo.FaFAFSA11 as fafsa on stud.ssn = fafsa.ssn left outer join
dbo.FaISIR11 as isir on fafsa.ssn = isir.originalssn
Order By
stud.lastname

Now fafsa_ss and isir_ssn are both char(9), null fields

I need to either cast or convert them to a field that will allow the SSN number to appear as 000-00-0000.

I wrote the following:

CAST (Cast(fafsa_ss AS (char(9),null) AS (Varchar(30),null)
(Cast(isir_ssn AS (char(9),null) AS (Varchar(30),null)

Which I am hoping will allow the fafsa_ss and isir_ssn to appear in the 00-0000-000 format, but I don't know if my code is correct and I don't know where to locate it. I have tried numerous different methods and I have bee researching this for days. Could someone please advise if this Cast function will work and if so where to place it inside the code so that the query will run?

Thank you.
Go to Top of Page
   

- Advertisement -