Question

Error converting data type varchar to float.

Asked by: user019

Declare @sqlquery1 float, @sqlquery2 float
set @sqlquery1='
select top 1 logspaceused from dbo.DBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc'

set @sqlquery2='
select top 1  logspaceused from
(select top 2 logspaceused,logdt from dbo.DBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc )as test order by  LogDT asc'

select (round(convert(float,@sqlquery1),4)  -
       round(convert(float,@sqlquery2),4)) as SQL
----
Declare @sqlquery1 real, @sqlquery2 real
set @sqlquery1='
select top 1 round(convert(float,logspaceused),4) as SQL1
from dbo.EnterpriseDBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc'

set @sqlquery2='
select top 1  round(convert(float,logspaceused),4)as SQL2 from
(select top 2 round(convert(float,logspaceused),4)as sql3,logdt
from dbo.EnterpriseDBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc )as test order by  LogDT asc'

select @SQLquery1-@sqlquery2


i am actually trying to get compare last 2 value to get % of growth in log file
(top1 - top2)
getting below error
Error converting data type varchar to float.
i tried as above 2 ways......
please let me know if u have any idea..

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-11 at 10:26:23ID24643908
Tags

T-SQL

,

SQL Server 2005

,

CTE

Topic

MS SQL Server

Participating Experts
3
Points
500
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Convert float to varchar
    I need to convert a float datatype to a varchar datatype. Right now I use convert(varchar, myFloatField). This works, however, I get the value with the exp format. I don't want this. If the varchar value is -1277739.244272, I don't want the converted float value of -1.277...
  2. insert varchar data into a float column.
    hi, how can i insert varchar (that holds numeric values e.g 200) data from one table into a float column in another table? thanks.
  3. Format float as varchar
    Hi, I have searched EE, but I must not be searching the correct keywords, as I can't find an answer to this one. I have a column of type float "my_ref" and I am just trying to append the value of this column to the value in the "name" column - which is a ...
  4. Error converting data type varchar to float
    is there a way to convert it from varchar to float? CONVERT(float,@Number) thx
  5. Convert Varchar to Float
    I am missing something but do not know what it is.... i am trying to convert the Amount Field which is a varchar to a float... please Help INSERT INTO tblLSWA15 (PolicyNumber, CompanyCode, EffectiveDate, PolicyStatus, Amount, Action, Description, CycleDate) SELECT [...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ralmadaPosted on 2009-08-11 at 10:57:03ID: 25071593

you are trying to use a float variable to store a string, hence the convertion error. Please give this a try:

(Please note that there's no need for the @sqlQuery variables)

select convert(float, (select top 1 logspaceused from dbo.DBLogspaceHist
			where server_id = 3 and database_name = 'bistage'
			order by  LogDT desc)) - 
	convert(float, (select top 1  logspaceused from 
			(select top 2 logspaceused,logdt from dbo.DBLogspaceHist 
			where server_id = 3 and database_name = 'bistage'
			order by  LogDT desc )as test 
			order by  LogDT asc)
		)
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-11 at 10:58:21ID: 25071602

Think you have incorrect single quotes (') which are causing the issue.  See the code snippet for correction.

Declare @sqlquery1 float, @sqlquery2 float
set @sqlquery1= (select top 1 round(convert(float,logspaceused),4) as SQL1
from dbo.EnterpriseDBLogspaceHist
where server_id = 3 and database_name = 'bistage'
order by  LogDT desc)
 
set @sqlquery2=(select top 1  round(convert(float,logspaceused),4)as SQL2 from 
(select top 2 round(convert(float,logspaceused),4)as sql3,logdt 
from dbo.EnterpriseDBLogspaceHist 
where server_id = 3 and database_name = 'bistage'
order by  LogDT desc )as test order by  LogDT asc)
 
select @SQLquery1-@sqlquery2

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: aneeshattingalPosted on 2009-08-11 at 10:59:59ID: 25071614

http://sequelserver.blogspot.com/2007/01/return-value-from-dynamic-sql.html


Declare @sqlquery1 float, @sqlquery2 float
declare @Sql1 nvarchar(1000), @Sql2 nvarchar(1000)
set @sql='
select top 1 @sqlquery1 = logspaceused from dbo.DBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc'

set @sqlquery2='
select top 1 @sqlquery1=  logspaceused from
(select top 2 logspaceused,logdt from dbo.DBLogspaceHist
where server_id = 3 and database_name = ''bistage''
order by  LogDT desc )as test order by  LogDT asc'

exec sp_ExecuteSQL @Sql1, N'@sqlquery1 float output', @sqlquery1 output
exec sp_ExecuteSQL @Sql2, N'@sqlquery2 float output', @sqlquery2 output

select (round(convert(float,@sqlquery1),4)  -
       round(convert(float,@sqlquery2),4)) as SQL

 

by: user019Posted on 2009-08-11 at 11:15:13ID: 25071757


thanks guys for the reply
ralmada: ur write no need of @sqlvariables the query worked fine
how does the query look if i try using @sqlvariables??

i have one more question here .. i have a list of logfilesize detalis from last few days in a table
i am actually trying to come with old data and get the percent growth of logfile ??
how can i do this?

did u get me??
thanks..


 

by: ralmadaPosted on 2009-08-11 at 11:28:13ID: 25071884

See mwvisa1's comment 25071602 for the alternative of using the variables.

 

by: user019Posted on 2009-08-11 at 11:45:05ID: 25072035

Thaks for the reply..
i tried as mwvisa1's reply

Declare @sqlquery1 float, @sqlquery2 float
set @sqlquery1= (select top 1 round(convert(float,logspaceused),4) as SQL1
from dbo.EnterpriseDBLogspaceHist
where server_id = 3 and database_name = 'bistage'
order by  LogDT desc)
 
set @sqlquery2=(select top 1  round(convert(float,logspaceused),4)as SQL2 from
(select top 2 round(convert(float,logspaceused),4)as sql3,logdt
from dbo.EnterpriseDBLogspaceHist
where server_id = 3 and database_name = 'bistage'
order by  LogDT desc )as test order by  LogDT asc)
 
select @SQLquery1-@sqlquery2

getting below error
Invalid column name 'logspaceused'.
for the line <<set @sqlquery2=(select top 1  round(convert(float,logspaceused),4)as SQL2 from >>

can u pls help in this too

i have one more question here .. i have a list of logfilesize detalis from last few days in a table
i am actually trying to come with old data and get the percent growth of logfile ??
how can i do this?

 

by: mwvisa1Posted on 2009-08-11 at 11:46:57ID: 25072052

<<i am actually trying to get compare last 2 value to get % of growth in log file>>
<< have a list of logfilesize detalis from last few days in a table
i am actually trying to come with old data and get the percent growth of logfile>>

As ralmada originally suggested, you don't need to use variables, you can accomplish what you want in one query.  For example, you could do something like the below.

-- use select top(2) ... to get just last two values
select LogDT, logspaceused
, case 
   when prev_logspaceused <> 0 
      then (logspaceused - prev_logspacedused) * 100.0 / prev_logspacedused 
   end as pct_growth
from (
	select LogDT, logspaceused
	, coalesce((
	   select top 1 logspaceused
	   from dbo.DBLogspaceHist h2
	   where h2.server_id = h1.server_id 
		and h2.database_name = h1.database_name
		and h2.LogDT < h1.LogDT
	   order by LogDT desc
	), 0) as prev_logspaceused
	from dbo.DBLogspaceHist h1
	where server_id = 3 and database_name = 'bistage'
) t
order by LogDT desc

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-11 at 11:49:29ID: 25072084

<<Invalid column name 'logspaceused'.>>

This error is because of the derived table (inner most query) aliases the logspaceused column as 'sql3' but then you referred to it as 'logspaceused' in outer query.  It was my fault for copying and pasting and not commenting on or correcting that previously.

 

by: ralmadaPosted on 2009-08-11 at 11:55:31ID: 25072148

Using mwvisa's first approach. I would do it like this (see attached).

regarding >>i have a list of logfilesize detalis from last few days in a table
i am actually trying to come with old data and get the percent growth of logfile ?? <<

I'm not following you. Can you please post an example?

Declare @result1 float, @result2 float
 
select @result1 = convert(float, (select top 1 logspaceused from dbo.DBLogspaceHist
			where server_id = 3 and database_name = 'bistage'
			order by  LogDT desc))
 
select @result2 = convert(float, (select top 1  logspaceused from 
			(select top 2 logspaceused,logdt from dbo.DBLogspaceHist 
			where server_id = 3 and database_name = 'bistage'
			order by  LogDT desc )as test 
			order by  LogDT asc))
 
select @result1 - @result2

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:

Select allOpen in new window

 

by: user019Posted on 2009-08-11 at 11:57:02ID: 25072160

how to get the prev_logspacedused detalis every time
(select top2).....??

 

by: mwvisa1Posted on 2009-08-11 at 12:11:17ID: 25072297

Not sure I understand your last question.  Please run my query and see what the results look like.  Then if you are wanting just the last two still, you can just add the phrase 'top(2)' in between 'select' and 'LogDT'.

 

by: ralmadaPosted on 2009-08-11 at 12:13:30ID: 25072314

hmmm, I agree with mwvisa1, your second question is not clear. Can you please post an example as well as the structure of DBLogspaceHist?

 

by: user019Posted on 2009-08-11 at 12:15:22ID: 25072326


i mean how to get the 'prev_logspacedused'  values because its the same column name logspacedused right ?

do i need to use this query to get previous value (select top 2 logspaceused,logdt from dbo.EnterpriseDBLogspaceHist )

how can i compare last five days value and get the %growth??

 

by: mwvisa1Posted on 2009-08-11 at 12:28:07ID: 25072435

Maybe you missed my post here -- http:#25072052.  Please run this code and see as it should have what you need to get the prev_logspacedused.  If the value is in a different table, then will need more information, but showed you an example with same table name in post I showed above.  Please review and adjust table and column names according to your actual environment.

 

by: user019Posted on 2009-08-11 at 13:18:56ID: 25072911

thanks for the reply

my table structure is as below

LogDT                     Serverid            Databasename            Logsize              LogSizeUsed

09-08-10                     3                      bistage                     8986.31              1.6613  

09-08-10                     3                      bistage                     8986.31               1.6629

09-08-10                      3                      bistage                     8986.31              1.67

09-08-11                     3                       bistage                     8986.31               1.81

09-08-11                      3                      bistage                     8986.31                1.98


i want to compare last 5 or 6 values and get the %used
Here there will be no column like 'prev_logspacedused'prev_logspacedused right?
it same logspacedused column
how can i get 'prev_logspacedused value do i need to use some self join and get .......pls let me know

getting the error because there is no column 'prev_logspacedused'

 

by: ralmadaPosted on 2009-08-11 at 13:34:53ID: 25073113

Are you using SQL 2005? If so, then you can get the %used per each line.

;with CTE as (
	select LogDT, Serverid, Databasename, Logsize, LogSizeUsed, row_number() over (order by LogDT) rn
	from DBLogspaceHist
)
select a.LogDT, a.Serverid, a.Databasename, a.Logsize, a.LogSizeUsed, case when a.LogSizeUsed <> 0 then ((b.LogSizeUsed - a.LogSizeUsed)/a.LogSizeUsed) * 100 else 0 end as PercentageIncrease
from CTE a
inner join CTE b on a.ServerID = b.ServerID 
where b.rn = a.rn + 1 and a.server_id = 3 and a.database_name = 'bistage'

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: mwvisa1Posted on 2009-08-11 at 13:38:38ID: 25073164

If you look at the code, I have "as prev_logspaceused" which is where prev_logspaceused is coming into play.  It is an alias.

Ramalda is using my same approach but for SQL Server 2005, which I would highly recommend if you have newer version of SQL as you can clearly see it is much smaller code.

 

by: mwvisa1Posted on 2009-08-11 at 13:40:08ID: 25073183

My concern with your data is I don't see timestamps and you have multiple entries per day.  This will interfere with the accuracy of this report.  Is there a better column to use for sequencing of rows?

 

by: ralmadaPosted on 2009-08-11 at 14:03:19ID: 25073424

>> This will interfere with the accuracy of this report.  Is there a better column to use for sequencing of rows? <<

I agree with mwvisa1, I would just add that because in the example provided there is no better ID column, I have used the row_number() function to create it on the fly.

 

by: user019Posted on 2009-08-11 at 14:16:25ID: 25073543

thanks

i am getting below result from ralmada query..... this does not look like actual result right

logpaceUsed             PercentgeIncrrease
 1.661396                           326.9147
 1.66291                             326.5259
1.670658                            324.548
1.819391                            289.8415
1.923211                            268.7969

 

by: mwvisa1Posted on 2009-08-11 at 15:01:15ID: 25073941

Try like this instead, it is using my original approach but with a common table expression since you appear to have SQL Server 2005+.

;with cte as (
  select *,
  -- replace LogSizeUsed with column that correctly holds order per day
  -- not needed at all if LogDT has timestamps
  row_number() over (partition by serverid, databasename order by LogDT, LogSizeUsed) rn
  from DBLogspaceHist
) select a.LogSizeUsed AS LogspaceUsed
, cast(case 
   -- avoid any divide by zero errors
   when coalesce(b.LogSizeUsed, 0) <> 0
      then (a.LogSizeUsed - b.LogSizeUsed) * 100.0 / b.LogSizeUsed 
   end as decimal(10,4)) as PercentgeIncrrease
from cte a
left join cte b on a.rn = b.rn+1
  and a.serverid = b.serverid 
  and a.database_name = b.database_name
where a.server_id = 3 and a.database_name = 'bistage'

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: user019Posted on 2009-08-11 at 16:14:15ID: 31614334

thanks..

 

by: user019Posted on 2009-08-11 at 16:20:28ID: 25074453

thanks a lot....... it looks fine now

yep i am using 2005
and logDt has timestamp

if u dont mind can u briefly explain me the query
mainly
select *,
  row_number() over (partition by server_id, database_name order by LogDT,
LogSpaceUsed) rn
  from dbo.EnterpriseDBLogspaceHist ------- what does this part get ? whats partition by?

select a.server_id, a.database_name, a.LogDT,a.logsize,
a.LogSpaceUsed AS LogspaceUsed
, cast(case
   -- avoid any divide by zero errors
   when coalesce(b.LogSpaceUsed, 0) <> 0  ----------whats  coalesce do here??
      then (a.LogSpaceUsed - b.LogSpaceUsed) * 100.0 / b.LogSpaceUsed  ---- b ? how does it take secondline here
   end as decimal(10,4)) as PercentgeIncrrease
from cte a
left join cte b on a.rn = b.rn+1 -- cte b??
  and a.server_id = b.server_id
  and a.database_name = b.database_name

thanks .............

 

by: user019Posted on 2009-08-11 at 16:33:22ID: 25074538

i will remove the where clause and run against all database it works fine right??

 

by: mwvisa1Posted on 2009-08-11 at 16:38:40ID: 25074574

Ok, since LogDT has timestamps then you can get rid of the second sort in the OVER statement but will explain the rest.


;with cte as (
  select *,
  -- replace LogSizeUsed with column that correctly holds order per day
  -- not needed at all if LogDT has timestamps
  row_number() over (partition by serverid, databasename order by LogDT) rn
  from DBLogspaceHist
)

The above portion of the query is a common table expression (CTE) (i.e., WITH ...) that allows you to create a virtual table of your data.  Would be same as if you took the query inside the parenthesis and made it a view or a temp table.  This gives added benefit over derived table as you can use it more than once in the outer query without a lot of ugly coding.  

The row_number() function inside this CTE is used in conjunction with the analytical over() clause to sequence your rows and give you a nice numerical field you can depend on.  In other words, I now that the row after row one has rn = 2, then rn = 3, etc.

The partition within the over() clause is the grouping.  Without this, you would get the rows sequenced as they appeared in the table by the 'order by LogDT'.  This is fine if you only have data from same serverid and database; however, the partition will treat each serverid and database combination as a new sequence, so you can have row 1 for serverid = 3 and database = 'bistage' and row 1 for serverid = 3 and database = 'test'.

For more information see this ref.: http://msdn.microsoft.com/en-us/library/ms189461.aspx.

select a.LogSizeUsed AS LogspaceUsed
, cast(case
   -- avoid any divide by zero errors
   when coalesce(b.LogSizeUsed, 0) <> 0

Coalesce is like isnull() function.  It will take the first non-null value between the columns result and literal 0.  Table aliased with 'b' identifier is representing the data in the row previous to the one we are on.  This is achieved in the join by 'a.rn = b.rn+1' which is same as 'b.rn = a.rn-1' so on row 1 the matching b would have to have a rn = 0.  Since there is no rn = 0, the previous row is NULL.  This is appropriate since your first record isn't increasing from anything so it should be NULL.

Consequently, what if there is a previous row, but the LogSizeUsed is 0.  You will get a divide by 0 error.  Therefore, I use coalesce(previous_value, 0) <> 0 to kill two birds with one stone as both NULL and 0 will be filtered out.

      then (a.LogSizeUsed - b.LogSizeUsed) * 100.0 / b.LogSizeUsed

b.LogSizeUsed is from the previous record, see above comment on how.

   end as decimal(10,4)) as PercentgeIncrrease
from cte a
left join cte b on a.rn = b.rn+1

This is the advantage of using a CTE that I declared above.  I am self joining the CTE that we aliased as cte (could be called c, t, or whatever you want -- just happens to be cte here so don't let that confuse you) to itself so to keep things from being ambiguous, one is called a and the other b.

  and a.serverid = b.serverid
  and a.database_name = b.database_name
where a.server_id = 3 and a.database_name = 'bistage'

 

by: mwvisa1Posted on 2009-08-11 at 16:40:17ID: 25074581

Because of the partitioning, the results should work perfectly fine without the where clause.

;with cte as (
  select *,
  -- replace LogSizeUsed with column that correctly holds order per day
  -- not needed at all if LogDT has timestamps
  row_number() over (partition by serverid, databasename order by LogDT, LogSizeUsed) rn
  from DBLogspaceHist
) select a.*
, cast(case 
   -- avoid any divide by zero errors
   when coalesce(b.LogSizeUsed, 0) <> 0
      then (a.LogSizeUsed - b.LogSizeUsed) * 100.0 / b.LogSizeUsed 
   end as decimal(10,4)) as PercentgeIncrrease
from cte a
left join cte b on a.rn = b.rn+1
  and a.serverid = b.serverid 
  and a.database_name = b.database_name

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

Select allOpen in new window

 

by: user019Posted on 2009-08-11 at 17:28:07ID: 25074821

thanks a lot for the explanation .....i will have a look into it

can u pls look into my other SQLQuery issue i have in below link..
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24643983.html

Thanks....

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...