Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4118
  • Last Modified:

Print INT in sql server 2005

Hello experts,

How can I print an int?

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

0
thewayne73
Asked:
thewayne73
  • 4
  • 2
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Try this:

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

Hope this helps
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Since you are concatenating it with a string 'prior: ', it needs to be casted to char or varchar for the + expression to work
0
 
thewayne73Author Commented:
i tried print 'prior: ' +  cast(@rp_prior as varchar(20))

..but it gives me a value of 1 instead of 121673441771
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Are you sure @@rowcount is 121673441771 instead of 1 because @@rowcount value will be passed to @rp_prior and printed out
0
 
thewayne73Author Commented:
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
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now