ONE ZERO ZERO -------&&> One Hundred = Nice String Formula !
Feb 21, 2008
Im trying to build myself a report that recieves a values as worded text e.g
zero zero one zero zero
it would be nice if i write some clever bit of code that would convert this to
One Hundred
Has anyone come up against this before, or could point me in the direction of a tutorial, i would appreciate it
thank you in advance
Jonny
View 6 Replies
ADVERTISEMENT
Jun 18, 2007
In 'MyTable' I have the following columns...
TotalNumber (numeric)
Weighting (numreric)
Hours (numeric)
Minutes (numeric)
Formula (nvarchar)
'Formula' column stores a literal string of the formula that may include some, none or all of the previous columns or be NULL.
Here are some examples of the actual strings it stores...
Weighting*Hours
Weighting+(TotalNumber*Hours)
Weighting*Hours)+(TotalNumber*2)
etc etc
All I want to do is create a UDF that will evaluate these strings as math formula and return the value depending on the values of the other columns in the row.
Bear in mind that there may not be a string formula at all for some rows, in which case the value of teh Hours column alone should be the result.
I can do this in vb using the 'Replace' function but am having difficulty in translating it over to T-SQL.
Here is the vb version i use in Ms Access...
getFormula(strDutyType As String, dblTotalNumber As Double, dblWeightingAs Double, dblHours As Double, dblMinutes As String, strFormula As Variant)
If IsNull(strFormula) Or strFormula = "" Then
getFormula = dblHours
Exit Function
End If
'Create the expression string with literal values
strExpression = Replace(strFormula, "TotalNumber", _
CStr(dblTotalNumber), , , vbTextCompare) _
strExpression = Replace(strExpression, "Weighting", _
CStr(dblPF), , ,vbTextCompare)
strExpression = Replace(strExpression, "Hours", _
CStr(dblHours), , , vbTextCompare)
strExpression = Replace(strExpression, "Minutes", _
CStr(dblMinutes), , , vbTextCompare)
'Evaluate the math of the literal expression
getFormula = Eval(strExpression)
-----------
Many Thanks
View 1 Replies
View Related
Mar 25, 2008
Hi guys,
I have a large text that can have some ENTER character inside of it. The problem is that the text must be inserted into a txt file in a single row. So what I need is to find those ENTER character and replace them with a space so as to have the whole string in one row.
How can I build that formula in derivide column?
Thanks for your help
View 10 Replies
View Related
May 31, 2005
Basically, I have a table with a column that stores mathematical formulas in string format. When my UDF is executed, it needs to select an appropriate formula from this table and evaluate it using values that are stored in local variables.Â
Look at the example below:
Suppose I have a string named @vcFormula that contains the following:"@dVar1 + @dVar2 / @dVar2"Now suppose I have a variable named @dVar1 that contains a value of 1.0, and variable @dVar2 contains a value of 2.5. I can use the REPLACE function to change my original string to look like this:"1.0 + 2.5 / 2.5"
Now I want to execute this string and find the numeric result, placing it in a variable named @dResult. The following works, but presents a problem:CREATE TABLE #Result (dResult decimal(20, 10))INSERT #Result EXEC('SELECT ' + @vcFormula)SELECT @dResult = dResult FROM #ResultThe problem with using this method comes from the fact that I need to be able to evaluate @vcFormula from within a user-defined function, but temporary tables are not allowed inside UDF's.Â
So I attempted to change the temporary table above into an instance of the TABLE data type. This didn't work either because EXEC cannot be used to populate instances of the TABLE data type. Then I came up with the bright idea to put the code above in a SP and call the SP from the UDF, but of course UDF's are not allowed to call SP's. Specifically, is there any way to execute a command/formula that is contained within a string other than by using EXEC?Â
View 10 Replies
View Related
Jul 20, 2005
Hi,I am trying to convert string entered in a field to uppercase usingits formula property.I know it can be done using trigger but still I want to use formulaproperty to achieve the same.Any help will be greatly appreciated.-Max
View 3 Replies
View Related
Sep 16, 2015
First off, I know this is a presentation issue. Second, no, I can't force a change on my source systems.
Some of the systems that send my BI application data, send that data in all upper case like so "JOHN DOE". We have this horrible SQL function that goes through and makes sure that the first letter in a word is always uppercase and the rest of the letters are lower case. So my results are "John Doe".
As you can imagine this is dreadfully slow when executed a couple of hundred million times, but what are my options?
I have not used Data Quality Services yet, but the chart in BOL says a DQS SSIS cleansing task can do 1 million records in 2 hours on a given set of hardware. That is still pretty horrible.
I suppose I could cobble together a Script task in SSIS, but I am pretty sure clumsy dotNet is not going to be much faster.
CREATE FUNCTION [dbo].[udf_ProperCase](@UnCased varchar(max))
RETURNS varchar(max)
as
begin
declare @Reset bit;
declare @Ret varchar(max);
[Code] .....
View 14 Replies
View Related
Sep 1, 2015
In SQL reporting, How do I add the formula in the Formula bar?All the data is coming from a sproc.
View 3 Replies
View Related
Jun 14, 2006
hi guys,
i m a newbee in SQL. i wanted to know which is the nice book to start with? anyone got ebooks of SQL2005?
View 1 Replies
View Related
Sep 29, 2006
Very nice; that worked.
It seems like a lot of code for each date field, but we are up and running now.
View 1 Replies
View Related
Nov 20, 1998
In the SQL Object manager tools for sql server 4.21 there was a gui interface for running BCP where you could select tables and fields etc.
I haven't beem able to find abnything equivalent in sql 6.5 enterprise manager. Am I missing someting, or was this dropped?
Thanks.
Jerry Dunn
ViaHealth
jerry.dunn@viahealth.org
View 1 Replies
View Related
Jul 20, 2005
Hi(sorry this has turned into a bit of an epic...thought I'd as theexperts!)SQL 2k, sp3a. Dual xeon 2.4. 2 gig ram. everything on a 3 disk raid 5.Microsoft SQL Server 2000 - 8.00.760 (Intel X86)Enterprise Edition on Windows NT 5.0 (Build 2195: )Problem seems to be some extended procs that seemed to be running fineon a 'vanilla' install on a different server now seem to be failing.Failures occuring c 6 - 10 hours.Sometimes the failure logs as the xp failure with severity 20 that Ikindof expect :s. other times absolutely nothing is logged.There are a variety of error messages - or sometimes nothing at all.http://www.mapinfo.com/common/docs/.../SWMSS48_RN.pdfdescribes one of our issues, which seems to come out on the restartafter a failure:Error event id is 19011, Message "SuperSocket info:ConnectionListen(Shared-Memory (LPC)) : Error 5."That site suggests:[color=blue]>Workaround>Suggested solutions include:>• Obtain a hotfix from Microsoft (http://www.microsoft.com). You will[/color]need to >cite the 94302[color=blue]>reference number.>• Turn off shared memory in the client network configuration utility[/color]to >disable shared[color=blue]>memory.>• Replace the SQL Server SSMSLPCN.DLL with the SSMSLPCN.DLL[/color](8.00.540) from >SQL[color=blue]>Server 2000 Service Pack 2.[/color]- but I cant find any sensible information which describes this tocorrelate! Searching MS for that number (94302) came up with zip.The dll version we are running is 2000.80.760.0, although earlierversions are elsewhere on the server (disk images).Interesting to note that we seem to be able to replicate the 'leakage'of improperly closed handles on this version, but not on the oldserver runningthat dll version 2000.80.194.0. This I understood to have been fixedin sp3.On one failure we caught the following (involving our extended procs):2004-02-15 15:03:31.40 spid58 Error: 0, Severity: 20, State: 02004-02-15 15:03:31.40 spid58 Stored function'xp_Contest_CalculateScores' in the library 'e:sqlxpga_procs.dll'generated an access violation. SQL Server is terminating process 58..2004-02-15 15:04:32.14 spid64 Error: 0, Severity: 20, State: 02004-02-15 15:04:32.14 spid64 Stored function 'xp_XML_GetSubTree'in the library 'e:sqlxpga_procs.dll' generated an access violation.SQL Server is terminating process 64..2004-02-15 15:04:48.48 spid53 Using 'dbghelp.dll' version '4.0.5'*Dump thread - spid = 53, PSS = 0x472d7200, EC = 0x725fc098*Stack Dump being sent to e:sqlMSSQLlogSQLDump0001.txt* ************************************************** ******************************* BEGIN STACK DUMP:* 02/15/04 15:04:48 spid 53This was followed about a minute later by:2004-02-15 15:04:55.75 spid53 Stack Signature for the dump is0x1CC032652004-02-15 15:04:55.75 spid53 SQL Server Assertion: File:<recbase.cpp>, line=1378Failed Assertion = 'm_offBeginVar < m_SizeRec'.2004-02-15 15:04:55.89 spid53 Using 'dbghelp.dll' version '4.0.5'*Stack Dump being sent to e:sqlMSSQLlogSQLDump0002.txt2004-02-15 15:04:56.01 spid53 SqlDumpExceptionHandler: Process 2292generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQLServer is terminating this process.* ************************************************** ******************************* BEGIN STACK DUMP:* 02/15/04 15:04:55 spid 53As a side issue we have a number of 'initialisation of notify failed'notes.Any one have any clue about this?Might the DLL need rolling back?Is sp3a knacked for extended procs?Is there some daft setting I've missed :/Any good events to track in particular?Cheers all!
View 1 Replies
View Related
Dec 26, 2005
What happened to nice SqlDataAdapter.Fill method in ASP.net 2.0 + How can i now access and traverse trhough table.
ex : sqlDataAdapter.Fill(dataSetname.tblsname);
dataSet11.rows[][]
View 5 Replies
View Related
Jan 18, 2004
It's rather easy to combine resultset from the same table structure...we can either insert the entries or union the results.
But let's say you select different columns from different tables and want to combine them to form a new table, how would you do it (assuming you can't join those tables since they are not related), assuming they all return the same number of rows.
select col1 from table1
go
select col2 from table2
go
Now I want to combine them so table3 is made of col1 and col2.
View 4 Replies
View Related
Feb 21, 2008
Here's a nice puzzle for all you masochistic programmers LOL.
Actually, it's just something that's been giving me problems and I know this forum has some amazing programmers who will probably find my problem to be easy.
I'm using 2005.
Simply put...
Here's the data:
ID Start End X
123 10 15 a
123 9 10 b
123 11 18 d
123 14 16 z
123 19 21 x
234 16 18 bb
I'd like to roll up overlapping start and end numbers into one set.
So here would be the output:
ID Start End [Ttl X]
123 9 18 4
123 19 21 1
234 16 18 1
The way I'm thinking of attacking this is maybe a combination of RowNumber & a CTE of some sort.
Please no loops or cursors, or extra tables.
Any ideas guys/gals?
Thanks a mil,
Denvas
View 5 Replies
View Related
Jan 18, 2008
Having a hard time writing a formula in RS...
Trying to say if the funding date is equal to today or before the beginning of the month then sum the loan amount.
Looking for something like this SUM(IF(Funding Date,>=Date(),Loan Amount))
Know it not right but someone please help!
View 1 Replies
View Related
Jan 26, 2008
I am create a database and want to store some value automatically in some field i.e say i have 3 column 1) salary(int),2)tax(int) and 3rd field total salary(float) . i want to automatically fill total salary field as Column1-Column2 while i daont have any Idea How to do that?
please help me?
any idea or tutorial..example anything...
View 3 Replies
View Related
Nov 17, 2007
hi,my users can make posts in my web application, i mean they fill a form and the information they filled will be saved in sql server 2000 and can be shown in web application,now i want to give each post an Id and save it in the database, how can i do that? does sql server have the abilities or i should do sth in my c# application
thanx
View 1 Replies
View Related
Oct 2, 2005
i wonder what is the best approach to use !!!i have creditLimit column in Customer Table the default value will be 500 and this limit to allow users to send sms from my website ..... every month they will be allowed to send 500 sms referring to the credit limit column.... now !!if the user sent today some sms and after few days sent another 20 and after one week he sent 150 SMS as a total so that means he has only 350 SMS as credit to use this month!!!so what is the best approach to implement this solution ? shall i have another field in the table called 'CreditUsed' and that will be updated each time the user will send SMS and this value will be compared with the credit limit ORi use the formula for the column to calculate the credit left and do the maths !!!what is the best approach as you think ???thnaks for reading this question !!
View 7 Replies
View Related
Mar 30, 2006
hi there.
I have asked this question before in a different section of the forum without much reply, and its probably because i was asking the wrong people.
I need to calculate a qouta for an election.
SqlCommand SqlCmd1 = new SqlCommand("SELECT count(vote)FROM PRTest", SqlCon1);
int quota = (count(Vote) + 1) / ((11) + 1);
My problem is this: how to i get the count(vote) value from the Sql Statement to the formula.
View 2 Replies
View Related
May 10, 2006
This does nothing:([rush24] + [rush6] + [addLocationsTotal] + 50)
This gives me my total correctly:([rush24] + [rush6] + 50)
All column are numeric(9) except the "total" column which is numeric(13).
Why is this happening?
View 1 Replies
View Related
Jun 13, 2002
I want to use the proprity Formula related to a column propreties :
Exempel : table XFRS i want to pupulate the field XF2 (int 4) using the value of another Field XF1 (int 4) Which is an identity field.
But When i try to insert into the table XFRS then i had an error
"Insert faild because the following set options have incorrect settings"
'ARITHABORT'"
Anyone to help me ? Thinks
View 1 Replies
View Related
Nov 3, 2004
Can anyone tell me how to find out if a column is a 'formula' or computed column - and what the formula is?
sp_columns @table_name = 'table' gives me most of the stuff I want but it doesn't show what the formula is for any formula columns...
Cheers in advance,
View 1 Replies
View Related
Apr 10, 2008
I have a quick question. created a report with this formula below. It works when I put a date range from 1-1-2007 to 2-1-2007, but when I put in a date range of 03-01-2008 through 03-31-2008. i get an error message of arithmetic overflow error converting numeric to data type numberic.
So instead of haveing the formula below be (4,2) I put it as (5,2) and now it work. Why is that?
CAST(clm_sppo / clm_tchg * 100 AS decimal(4, 2)) AS PercentSavings
View 3 Replies
View Related
May 26, 2008
in front end application,iam using pivot table,there is no option to create the growth rate calcuation/formula in FE.
my table data consists like below:
country_name Revenue PERIOD_TYPE_OUT Amount_out
UK Solutions01 Apr 2007 To 31 Mar 200856.83000000
UK Solutions01 Apr 2006 To 31 Mar 2007116.07000000
while iam using the cross tab in front end application data view is coming as
country_name
01 Apr 2006 To 31 Mar 2007 01 Apr 2007 To 31 Mar 2008
solution solution
uk 116.07 56.83
Actual o/p should be:
01 Apr 2006 To 31 Mar 2007 01 Apr 2007 To 31 Mar 2008 Growth
solution solution
uk 116.07 56.83 -0.51
can anybody tell how to calcualate growth in stored procedure level formala for calculating growth rate
is :
(56.83-116.07)/116.07
([current year]-[previous year])/[previous year]
View 2 Replies
View Related
Apr 18, 2007
i have two tables .Table 1 contains certain columns with values.Table 2 shud get those data from table1 into its column and display the calculated result. Any idea how do i go abt it,bcuz table2 shud contain a formula so as to calculate.
View 5 Replies
View Related
Mar 8, 2008
Hi,
I want to store, mathematical formulas, in SQL, now how can i store integration signs, fractions, and various types of other symbols.
The output must be on html page using ASP. and also on VB frontend.
Pls. assist.
View 5 Replies
View Related
Mar 31, 2008
SELECT ID, CalibScoreAVGQA,
COUNT(CalibScoreAVGQA) AS Expr1
FROM dbo.TechPhonesCalibScoreAVGQA
Any idea why I'm getting "dbo.TechPhonesCalibScoreAVGQA.ID is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause
View 8 Replies
View Related
Jan 26, 2006
Hi,I have three tables in the following structure (simplified):Table 1: Containing the customers-------------------------------------------------create table Customers([cusID] int identity(1, 1) not null,[cusName] varchar(25) not null)Table 2: Containing the customer data fields---------------------------------------------------------------create table Data([datID] int identity(1, 1) not null,[datName] varchar(25) not null,[datFormula] varchar(1500))Table 3: Containing the customer data values-----------------------------------------------------------------create table Values([cusID] int not null,[datID] int not null,[valValue] sql_variant)In this structure the user can add as many data fields to a customer ashe wants (e.g. Country, City, Email, Phone, ...). I have added triggerswhich create a view similar to a pivot (I am working in SQL 2000) andadd triggers to the view so it is insertable, deletable and updateable.What I would like to do, is allow the user to create new fields wherethe values are based upon a calculation. This calculation would be donethrough a formula similar to what he would do e.g. in excel (thisformula is stored in the dimFormula field then).An example might help. Let's assume the user created a field 'Sales'(containing last year's sales) and 'Invoices' (containing the number ofinvoices that were created for him last year). Now, he wants to createa field 'AvgSales' with the formula '[Sales]/[Invoices]'.(Note that through adding these data fields, the above view was created(let's assume it is called vw_Customers and contains the columns [ID],[Name], [Sales], [Invoices], [AvgSales]).What I am looking for is a function which can parse this formula into at_sql query which runs the calculation. So, the formula'[Sales]/[Invoices]' would be translated into (let's assume there areno records with NULL or zero invoices):update vw_Customersset [AvgSales] = [Sales]/[Invoices]from vw_CustomersI am able to do the above with simple calculations (where you can evenuse sql functions e.g. year, len, ...). Now I would like to take thisone step forward into the possibility of using functions with morevariables.For example. Let's assume, the user wants to add a rating (field called'Rating') to his customers based upon the result of 'AvgSales. Heenters the formula 'if([AvgSales] > 2500, 'A', 'B')'.If anyone could help me on this, I would be very grateful. Thanks.M
View 3 Replies
View Related
Feb 17, 2006
env: sql server 2000objective:add a formula for an INT column to the FORMULA field or the DEFAULTVALUE field in DESIGN VIEW.all of the following attempts failedIIF (columnName = 0, "1", columnName + 1)IIF (columnName = 0, 1, columnName + 1)IIF (0, "1", columnName + 1)caveat: cannot use IDENTITYREASON: I'd like have sets of repeatable values for this row, e.g.set a1 -- row 12 -- row 2345set b1 -- row 623set c1 -- row 9234Underlying rationale is to support OO design I understand probably it'sgoing to be huge headache for lots of people down the road but ...TIA.
View 3 Replies
View Related
Jul 20, 2005
HI,I have a problem in formula column.I have 8 1 bit varibles in a tablefor ex: Flag1, falg2, flag3 ...Flag8Now I want to create another variable as a small integer and copy allthe flgas to that field.For ex:(flag1 << 0x80) | (flag2 << 0x40) | ..... | flag8I tried all possible ways?Let me know how to write the formula for this column.Thanks,Venkat.
View 1 Replies
View Related
Jul 20, 2005
Hi,I would like to create a calculated column using the formulasection for a table. I am having some trouble doing this.The table's name is ReportParameter. The calculated column's name istbcalculatedcolumn and tb1 and tb2 are boolean columns in the table.I would like to use an If then statement such as the following (inpsuedo code):If tb1 = 1 then tbcalculatedcolumn = 1Elseif tb2 = 1 then tbcalculatedcolumn = 2EndifThanks for the help,Bill
View 6 Replies
View Related
Oct 30, 2007
fellows
i am working in this formula
((4 * dbo.Drillability.WEIGHTONBIT)
/ (POWER(PD_Data.dbo.db_drill_hole_base.loaded_diameter, 2) * PI()) + (8 * dbo.Drillability.RPM * dbo.Drillability.TORQUE)
/ (POWER(PD_Data.dbo.db_drill_hole_base.loaded_diameter, 2) * dbo.Drillability.ROP)) * 0.006894757 AS SPEC_ENERGY_MPa
but my problem is that i have ceros in some records, i was thinking in to use ISNULL but when i tryed to run the query I got error close to 'as'........someone can help me whit this.
cheers
edwin
View 12 Replies
View Related
Apr 4, 2008
hy guys
i am trying to calculate a formula in sql, but
in the field lbs1 sometimes has ceros and the lbs2 sometimes has ceros as well
the resul of the formula is null, but this is supposed to be a value. the rest of fields always have data.
SQRT((((db_linear_density_1.[Linear density_1] * dbo.Assay_acquire.[lbs1(Kg)] + PD_Data.dbo.db_linear_density.[Linear density_2] * dbo.Assay_acquire.[lbs2(Kg)]) / (dbo.Assay_acquire.[lbs1(Kg)] + dbo.Assay_acquire.[lbs2(Kg)])) * ((dbo.HOLELOCATION.DEPTH - PD_Data.dbo.drillhole_base_MOR_MET_2004.stem) * 0.3048)) / (((dbo.Assay_acquire.[lbs1(Kg)] + dbo.Assay_acquire.[lbs2(Kg)]) / dbo.Assay_acquire.holetons) * (dbo.Assay_acquire.holetons / (dbo.HOLELOCATION.DEPTH * 0.3048 * dbo.Assay_acquire.[holearea(m2)]))) / 15) * 0.9325
cheers
View 3 Replies
View Related