Solved

Print INT in sql server 2005

Posted on 2009-05-18
6
4,091 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.​
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now