Solved

Print INT in sql server 2005

Posted on 2009-05-18
6
4,097 Views
Last Modified: 2012-05-07
Hello experts,

How can I print an int?

select @rp_prior = @@rowcount
print 'prior: ' +  @rp_prior

0
Comment
Question by:thewayne73
  • 4
  • 2
6 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24412325
Try this:

print 'prior: ' +  cast(@rp_prior as varchar(10))

Hope this helps
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24412332
Since you are concatenating it with a string 'prior: ', it needs to be casted to char or varchar for the + expression to work
0
 

Author Comment

by:thewayne73
ID: 24412348
i tried print 'prior: ' +  cast(@rp_prior as varchar(20))

..but it gives me a value of 1 instead of 121673441771
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24412430
Are you sure @@rowcount is 121673441771 instead of 1 because @@rowcount value will be passed to @rp_prior and printed out
0
 

Author Comment

by:thewayne73
ID: 24412496
i have a select statement that SUMS the value of a field.  I want to grab that sum and put it into a variable.  how can i do that?


0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24412550
Since you haven't provided out the entire query, I am giving out a sample example:

declare @a int,
@b int,
@c int;

set @a = 10;
set @b = 25;

set @c = @a + @b;
-- set @c = (select sum(colname) from tablename);
Print '@c is : '  + char(@c as varchar(20);

Check out the commented line for your reference
This should guide you out properly.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question