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
 print not working

Author  Topic 

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-24 : 22:12:09

pl help me in correcting the syntax for print.

declare @a as int,
@b as int,
@c as int;
set @a=100
set @b=230
set @c=(@a/@b)
print 'value of c=',@c

Error message;
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near ','.


tvspsekhar

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-03-24 : 22:34:54
can not implicit convert


declare @a as int,
@b as int,
@c as int

set @a=100
set @b=230
set @c=(@a/@b)
print 'value of c='+CONVERT(varchar, @c)
Go to Top of Page

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-24 : 22:40:15
Thank U namman. But the value of c is coming as 0
declare @a as int,
@b as int,
@c as int,
@temp varchar(50)

set @a=100
set @b=230
set @c=(@a/@b)
set @temp = 'value of c='+CONVERT(varchar, @c)
print @temp --'value of c=',@c

on execution:

value of c=0


tvspsekhar
Go to Top of Page

namman
Constraint Violating Yak Guru

285 Posts

Posted - 2010-03-24 : 23:16:29
using decimal

declare @a as decimal(5,2),
@b as int,
@c as decimal(5,2)

set @a=100
set @b=230
set @c= @a/@b
print 'value of c='+CONVERT(varchar, @c)


value of c=0.43
Go to Top of Page

tvspsekhar
Starting Member

20 Posts

Posted - 2010-03-24 : 23:40:46
Thank U very much Mr namm

tvspsekhar
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-25 : 02:49:31
or


declare @a as int,
@b as int,
@c as int,
@temp varchar(50)


set @a=100
set @b=230
set @c= @a*1.0/@b
print 'value of c='+CONVERT(varchar, @c)
http://beyondrelational.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

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

- Advertisement -