Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math in SQL

Status
Not open for further replies.

nohandlesleft254

IS-IT--Management
Apr 19, 2006
58
GB
Hi,

Im using coldfusion and SQL server. I want to perform a multiplication by percentage on a field before i then run a WHERE on it. I have written out incorrect SQL of what i want to do - can anyone tell me how i actually need to do it!?

WHERE (CAST(Sum4 AS NUMERIC)+((CAST(Sum4 AS NUMERIC)/100)*100)) LIKE '%#Session.QuotesQuickfind#%'

Thanks
 
What type is Sum4?
What type is Session.QuotesQuickfind?
Thie expression doesn't make sence to me:
(Let say Sum4 is equal to 2:
(2+((2/100)*100))? what is this?
It is always = Sum4*2

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Ok the 100 is actually a variable so 100 could be a range of figures - and the sum is to work out x precentage of sum4, and add it to sum4. Both sum4 and Session.QuotesQuickfind are nvarhar. Sum4 will always be numeric (although DB holds as text) and Session.QuotesQuickfind is a freetype search field and can be anything.

I spose what im after is info on how to perform maths within SQL code.

Thanks
 
Code:
WHERE CAST((CAST(Sum4 AS NUMERIC)+((CAST(Sum4 AS NUMERIC)/100)*100)) as nvarchar(xxx) LIKE N'%'+Session.QuotesQuickfind+'%'
where xxx is desired length.
Something like that, not tested

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top