Solved

Print INT in sql server 2005

Posted on 2009-05-18
6
4,094 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query to display duplicates ? 6 38
SQL to update characters in table column 6 91
Fixed Length SQL Query Question 3 28
How does this SELECT query work 11 100
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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