January 6, 2011 at 11:23 am
Hi,
I have a sql query
###########################
selectcount(tot_files) (title 'Number of files=')
from month_test ;
#########################
the output will be
'Number of files= 4
########################
the output 4 is coming after 12 spaces..... is there any way to get that number immediately after '=' sign.
January 6, 2011 at 11:27 am
Cast/Convert the string to varchar.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 6, 2011 at 11:30 am
Can u provide me the solution
January 6, 2011 at 12:25 pm
gnaneshs (1/6/2011)
Can u provide me the solution
I'm not sure about that "title" bit you're using. Using the structure I'm accustomed to, it might look like:
declare @Title varchar(100) = 'Number of files=';
select @Title = @Title + cast(count(*) as varchar(100))
from month_test;
print @Title;
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
January 6, 2011 at 6:08 pm
toddasd (1/6/2011)
declare @a varchar(100)set @a = 'Number of files=4'
select substring(@a, 17, len(@a))
:blink:
--Jeff Moden
Change is inevitable... Change for the better is not.
January 6, 2011 at 6:12 pm
gnaneshs (1/6/2011)
Can u provide me the solution
GSquared gave you a correct solution but do you understand it? If not, I strongly recommend that you lookup the CAST function, the VARCHAR datatype, and the concatenation operator of "+" in Books Online. Assuming by your question that you're an absolute newbie with SQL Server, "Books Online" is the help system that comes with SQL Server.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 6, 2011 at 7:18 pm
Jeff Moden (1/6/2011)
toddasd (1/6/2011)
declare @a varchar(100)set @a = 'Number of files=4'
select substring(@a, 17, len(@a))
:blink:
To me, looks like he wanted the "4" from the string. So, you know, taking a shot in the dark at a black cat.
______________________________________________________________________________
How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.
January 7, 2011 at 6:38 pm
toddasd (1/6/2011)
Jeff Moden (1/6/2011)
toddasd (1/6/2011)
declare @a varchar(100)set @a = 'Number of files=4'
select substring(@a, 17, len(@a))
:blink:
To me, looks like he wanted the "4" from the string. So, you know, taking a shot in the dark at a black cat.
BWAA-HAAA!!!... understood. I sometimes take the same shot without the benefit of moonlight. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply