Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric to varchar issue 1

Status
Not open for further replies.

willydude

Programmer
Oct 24, 2006
123
US
I am having a very trying time trying to get a print statement to work with a conversion. I have verifed that when the query is run, there is data in the @PrevailingWage parameter. None of the following have worked. What am I missing?

Code:
print 'Prevailing ' + Convert(varchar (10), @PrevailingWage)

print 'Prevailing ' + Cast(@PrevailingWage as varchar)

print 'Prevailing ' + Coalesce(@PrevailingWage, '')

I have tried adapting the following from a previous post:
Code:
/*
select @f,convert(numeric(38,2),@f),
	convert(varchar(66),convert(numeric(38,2),@f))
*/
print 'pw' + (Select @PrevailingWage,
		Convert(numeric (6,3), @PrevailingWage),
		Convert(varchar (8), convert(numeric(6,3),@PrevailingWage))

Any help would be greatly appreciated.

Bill
 
What error are you getting with the first three options that you posted?

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Well, I am not getting an error msg for the Print statements, they are just not printing. At a minimum, I believe that I should be getting the:

Code:
'Prevailing '
part to print, but it's not.

It should read:
Code:
'Prevailing 7.25'

I have other Print statements in the same sproc that are working, it's just the few that I need to change from numeric to varchar. I am wanting them to print so I can see the value in the variable.

Now I am getting an error msg in regards to Client_PK_ID being NULL. I posted another Q under the heading of:

"Info from 2 unrelated tables into one with error msg." This post has some other code in it that might be helpful. Please note that I am now not getting the info in the second line of the results.

I can post the complete sproc if needed. Thanks for the help.

Bill
 
How about:
Code:
print 'Prevailing ' + Convert(varchar (10), ISNULL(@PrevailingWage,0))

print 'Prevailing ' + Cast(ISNULL(@PrevailingWage,0) as varchar(10))

print 'Prevailing ' + Coalesce(@PrevailingWage, '@PrevailingWage = NULL')

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
Borislav's sugestion would be my next step in testing.

If you get 0s when you run the procedure then the variable isn't getting set.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Boris and Denny,

Thanks for the help. I'm using the following:
Code:
print 'Prevailing ' + Convert(varchar (10), ISNULL(@PrevailingWage,0))

Is there a performance difference with any of these?

Thanks,

Bill
 
No, not really.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top