Solved

Print INT in sql server 2005

Posted on 2009-05-18
6
4,095 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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