T-SQL (SS2K8) :: Arithmetic Formula To Stuff Digits

Apr 6, 2015

I have a column which needs to be 9 digits long. The first four digits are independent from the other digits. The following digits need to be 5 and I have to add leading zeros if they're less than 5. This is an awful design and I'd love to change it but I can't.

SELECT Cg.Fiid,
--Original Formula
SUBSTRING( CONVERT( varchar, Cg.Fiid ),1, 4 ) + RIGHT( '00000' + SUBSTRING( CONVERT(varchar, Cg.Fiid ), 5, 10 ), 5 ),
--My solution
STUFF(Cg.Fiid, 5, 0, REPLICATE('0', 9 - LEN(Cg.Fiid)))
FROM (VALUES(71927),
(498932),
(498934),
(38061278))Cg(Fiid)

View 9 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Matching Value After Using STUFF

Aug 22, 2014

This is my code, table and result,

declare @t_JobNoticeID table (cvid int, JobNoticeID int)
insert into @t_JobNoticeID values(2456, 24);
insert into @t_JobNoticeID values(4000, 124);
insert into @t_JobNoticeID values(245, 9);
insert into @t_JobNoticeID values(2456, 19);
insert into @t_JobNoticeID values(4000, 904);
insert into @t_JobNoticeID values(4000, 11);
insert into @t_JobNoticeID values(24, 19);

[Code] ....

My question is -

How update statement looks like compare RESULT A1 with x_JobMatching?

So, my FINAL RESULT shown as follow,

CVIDJobNoticeIDisMatch
1925450
6590690
459130
2456191
4569110
40009041
24560
900240
24191

View 5 Replies View Related

T-SQL (SS2K8) :: Divide Using Formula From Different Table

Jan 23, 2015

I need to evaluate a formula in sql server 2008

Table 1 contains

Entity Value
A 2424053.500000
B 1151425.412500
C 484810.700000
Table 2 contains

Entity Formula
A (2100*(1-0.0668)*24*mday*10)
B (1000*(1-0.0575)*24*mday*10)
C (1260*(1-0.09)*24*mday*10)

Where mday is number of days taken from user

I need to calculate the output of value/formula for each entity can you provide me the query for the same

The datatype for formula column is varchar

I do not have the liberty to use cursors or loops.mday will be a input fromt the user say 'mday = 31' ..i need to divide the value in the first table with the computed value of the formula after replacement

View 1 Replies View Related

T-SQL (SS2K8) :: Arithmetic Overflow Error Converting Expression To Data Type Int

Mar 25, 2015

In my sql statement, I don't have any datatype as INT, when I run it, give me error as 'Arithmetic overflow error converting expression to data type int'.

example :
select column1, 2, 3 .....
from (select sum(float) as column1 , ....)

When I hop my cursor on top of column1, it shows (int,null)

View 4 Replies View Related

T-SQL (SS2K8) :: How To Perform Mathematical Formula Without Using Case

Sep 17, 2014

I am having 4 Columns Qty decimal(12,3),CF1 Decimal(12,3),CF2 Decimal(12,3),Flag TinyInt.

I want to perform following without using case if it is possible.

When value of Flag is 0 then Qty*(CF2/CF1)
When value of Flag is 1 then Qty

And i Don't want to use any functions like isnull,NullIf,IIF even not union or union all.How to do this calculation without using any function.

Actually i am having more then 100000 rows in table and if i use functions then my index might not be called.,that why want to avoid cases and functions.

View 9 Replies View Related

T-SQL (SS2K8) :: XQuery Syntax To Evaluate Math Formula

Feb 25, 2015

I want to evaluate a math formula inside of a function, so I can't use dynamic SQL.

I found that the query on an XML-variable with a literal works well.

DECLARE @sParsedFormula varchar(200);
DECLARE @xFormula xml;
SET @xFormula = '';
SET @sParsedFormula = '1+2';
SELECT @xFormula.query('3+3') , @xFormula.query('sql:variable("@sParsedFormula")')Output (1st value is correctly evaluated, 2nd not):
"6", "1+2"

I can't directly pass @sParsedFormula to the query otherwise I get "The argument 1 of the XML data type method "query" must be a string literal". What is the correct XQuery-syntax to evaluate the SQL:variable?

View 2 Replies View Related

T-SQL (SS2K8) :: Arithmetic Overflow Error Converting Varchar To Data Type Numeric Message When Field Is Decimal

Apr 3, 2014

I am trying to setup an indicator value for an SSRS report to show green and red values on a report, based on the NRESULT value. The problem I am facing is that I have several different CASE statements that have the same logic, and they are processing just fine. NRESULT is a decimal field, so no conversion should be necessary. I do not know why I am getting the "Arithmetic overflow error converting varchar to data type numeric." error message.

Below is the CASE statement where the error is occurring. It is in the part of the ELSE CASE. The first CASE works just fine when the ELSE CASE is commented out. If I also change the ELSE CASE statement to say "else case when LEFT(NRESULT,1) = '-' then '0'", then it processes fine, too, so it has to be something I am missing something in the check on negative values. I do need the two checks, one for positive and one for negative values, to take place.

case when LEFT(NRESULT,1) <> '-' then --This portion, for checking positive values, of the CASE statement works fine.
CASE WHEN LEFT(ROUND(NRESULT,2),4) between 0.00 and 0.49 THEN '2' --Green
ELSE CASE WHEN LEFT(ROUND(NRESULT,2),4) > 0.49 THEN '0' --Red
ELSE '3' --White
END
END
else case when LEFT(NRESULT,1) = '-' then --This portion, for checking negative values, of the CASE statement is producing the conversion error message.

[code]....

I checked the NRESULT field, and there are not any NULL values in there, either.

View 1 Replies View Related

T-SQL (SS2K8) :: Arithmetic Overflow Error Converting Numeric To Data Type Numeric

Jun 10, 2014

when I run below query I got Error of Arithmetic overflow error converting numeric to data type numeric
declare @a numeric(16,4)

set @a=99362600999900.0000

The 99362600999900 value before numeric is 14 and variable that i declared is of 16 length. Then why this error is coming ? When I set Length 18 then error removed.

View 2 Replies View Related

Reporting Services :: Add Formula To Formula Bar In Excel

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

AWE, /3gb And /pae Stuff

Jul 4, 2007

Hi all,



I'm running under Windows Server 2000 datacenter sp4 with sql server 2000 Sp4

on 16GB Ram.



I enabled the /PAE in the boot.ini file and also enabled the AWE and set the SLQ Server maximum memory to 6144.



Do I need to include the /3GB switch in the boot.ini file?



I'm a little bit confused with the article found on the site. http://support.microsoft.com/default.aspx/kb/274750

Here are the lines.

Use of the /PAE switch in the Boot.ini and the AWE enable option in SQL Server allows SQL Server 2000 to utilize more than 4 GB memory. Without the /PAE switch SQL Server can only utilize up to 3 GB of memory.
or-Use of the /3GB switch in the Boot.ini file allows SQL Server 2000 to use up to 3 GB of available memory.


Regards,

Larry

View 5 Replies View Related

Easy Stuff

Jul 1, 2004

hi.. guys this is simple for you guys how can i make ms access to display the current date in a col.... when i go to insert a new line i how can i make it so that its allready there? i dont have to type it??????

View 3 Replies View Related

Locale Stuff

Jan 25, 2005

Hi,

You might just be able to save me downloading and installing SQL Server French...

I'm having localization problems with some .NET code - and I might be able to solve the problem if I know how SQL is parsed in different locales. Say my table MyTable contains a float column FloatColumn. In English, I would say
SELECT * FROM MyTable WHERE FloatColumn = 2.3

If my locale was, say for argument's sake, French, would I have to write
SELECT * FROM MyTable WHERE FloatColumn = 2,3
???

Thanks for your help,
T

View 1 Replies View Related

Datetime And Other Stuff

Dec 12, 2005

Overview. Machine data is fed into DOWNTIMELOG via a Cimplicity. I do not have the ability to change the way that it goes in. It contains the time that a machine has stopped and where the stoppage has occurred. Via a web page I want to give the operator the amount of time the machine stopped. From that they will provide some more detail. As they enter time, I need to subtract what they entered from the total (DOWNTIMELOG). That is the reason I created ENTERED_TIME. [PDNTOTAL_TEMP_VAL0] hold the total time for each stoppage, [TOTTIME] is intended to hold the value that has been accounted for. [DWNCATEGORY_TEMP_VAL0] holds the category and matches up with [DWNCATEGORY]. Also, I need to match Date and Shift. The problem is that DOWNTIMELOG does not capture shift. However, 1st shift occurs between 700 and 1500, 2nd shift occurs between 1500 and 2300, 3rd shift occurs between 2300 and 700. 3rd shift presents a problem as it occurs across 2 dates. Could someone please help me with a query that provides the net between the two tables that is matched by date, shift and category?
CREATE TABLE [dbo].[DOWNTIMELOG] (
[timestamp] [datetime] NOT NULL ,
[DWNTIMESTAMP_VAL0] [varchar] (25) NULL ,
[UPTIMESTAMP_VAL0] [varchar] (25) NULL ,
[PDNHOUR_VAL0] [int] NULL ,
[PDNMIN_VAL0] [int] NULL ,
[PDNSEC_VAL0] [int] NULL ,
[PDNTOTAL_TEMP_VAL0] [int] NULL ,
[DWNMSG_TEMP_VAL0] [int] NULL ,
[DWNCATEGORY_TEMP_VAL0] [varchar] (50) NULL

CREATE TABLE [dbo].[ENTERED_TIME] (
[REC_ID] [int] IDENTITY (1, 1) NOT NULL ,
[DWNCATEGORY] [varchar] (50) NULL ,
[DWNMSG] [int] NULL ,
[ENTRYDATE] [smalldatetime] NULL ,
[SHIFT] [int] NULL ,
[TOTTIME] [int] NULL

View 4 Replies View Related

Reg Exp For Digits

Sep 18, 2005

Hi,This is not SQL Server database problem, however, net search has failedto generate a solution to the problem, I'm trying my luck at this NGnow.Problem, remove the special character, [ from text.e.g. text ="this is [1] and [stuff] and some [2] and hat [3] and dog"Desired result ="this is 1 and [stuff] and some 2 and hat 3 and dog"I know [[:digit:]] would find all the instances of digits insidebrackets such as [1], [2], [3]. However, I don't know how to get ridof the special characters of [ and ].Any regular expression expert out there?Thanks.Don

View 8 Replies View Related

Sql Automated Task Stuff

Jan 14, 2008

Where can i learn about making the sql server execute task when a certain situation happens. Like lets say make the server delete all entrys older than 40 days? Or have a entry deleted automatically when a certain situation happens like lets say it take 4 votes and a entry get deleted how do i make it do that automatically

View 2 Replies View Related

CHARINDEX And STUFF/REPLACE

Jul 23, 2005

Hello,I need to be able to replace only the first occurance of a space characterin a column.Reason being is the data in the column I am trying to replace seems to haveumpteen space characters after each entry, so a simple replace functionwill replace all the spaces after it with what I want!I have thought of RTRIM to get rid of the spaces after and then replace, Ihave also thought of CHARINDEX to find the first occurance of a space andSTUFF to replace it.I have done my homework on these functions!But I am having trouble writing such a statement,I've never written a query which would use more then one function on onecolumn you see and I am getting confused!I'll tell you what I want to do in simple stepsReplace only the first found space in a name column, but then if a name hasa middle initial that will be a problem,Replace that with a dot.then concatanate '@emailaddress;@emailaddress2' after itso when SQLServer does the select it will bring back something likejoe.bloggs@emailaddress;emailaddressBut I guess I'd also need joe.n.bloggs@emailaddress;emailaddressThe data in the column looks like this at the momentjoe bloggsBut I guess there may come a time when we havejoe n bloggs, just to complicate things!What is your advice, and how do I write a query like thisI have been playing around with it in Query Analyser but as I said I amgetting confused and need some help if you don't mindThanks a lot to all who reply :-)RegardsJayne

View 2 Replies View Related

I Need 2 Decimal Digits

Apr 14, 2008

Hello All,

Current Format :-
40.349.462.875.589.2100112127


Required Format
40.3049.4062.8075.5089.20100.00112.00127.00


Currently mine above row data type is float. i need two points after precisions.

Thanks

View 3 Replies View Related

Right 10 Digits From Column

Oct 7, 2014

Following function in not giving me correct output:

update dbo.raw
set PhnNumber = RIGHT(calling_pty,10)

What I want is....if in case column "calling_pty" i have values like 911111111111 so it should give me the output in column "PhnNumber" as 1111111111 means only right 10

View 3 Replies View Related

Smallmoney With 2 Digits

Jan 2, 2008

I have a table for products and the price field is smallmoney data type. When I view the data stored it shows it with millionths. How do I get it to store only hundredths?

View 2 Replies View Related

Add Digits To The Front

Jul 20, 2005

Hi all,I have a number like so 778625 and want to make this a more meaningfuldate (UK) so how difficult is it to add two digits in this case 19 tothe front of this number?Many thanksSam*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 3 Replies View Related

Why Does The Automatic Scripts That Are Generated Have So Much Stuff?

Dec 11, 2007

For example if I make a column not null the SQL Script generated.
Removes all indexes, keys, etc... than creates a temp tableThan moves the data into the temp tablethen deletes the old tablerenames the temp tableRecreate all the indexes, keys, etc...
Is there a structure reason for it? Like now that the DB is being alerted that the column is not null it wants to re insert all the data so it can re-organize it?
Because I can just write my own script to the effect of
ALTER [TABLE] [COLUMN] PARAM TYPE NOT NULLone line of script that seemingly does the exact same thing..
So I'm just curious when I change a column to non null why doesn't it just generate a simple one liner?

View 3 Replies View Related

Newbie - SQL Server Express And Other Stuff

Feb 16, 2008

Hi

View 1 Replies View Related

Use Stuff To Define Range Of Values?

Nov 13, 2014

I have this query that calculates the next possible shipping day, based on 3 conditions:

- It has to be a workingday (WORKTIMECONTROL: 1 workingday, 0 holiday) - marked green
- There might be extra days (@xdays) required by the process - marked blue
- Customer wants their goods to be shipped on special days - marked red:select TOP 1 Transdate
from WORKCALENDARDATE
where Transdate > @startday and WORKTIMECONTROL = 1 and DATEPART(WEEKDAY,TRANSDATE)-1 in (2,4) and

[code]...

So customer 123456 accepts shipping of goods only on tuesday and thursday as in the above example "... in (2,4)". Multiple shipping days means that the Subquery returns more than one record, which gives me a headache as I don't see how to integrate this portion into my query. I tried to use the stuff function as I formally need a result that can be provided that way; but the format is incorrect as it in varchar, while an array of integer is needed.

DATEPART(WEEKDAY,TRANSDATE)-1 in (select stuff((select ',' + CAST(DELIVERYDAY as nvarchar) from CollectiveShipment where custaccount = '123456'
for xml path('')),1,1,''))

View 2 Replies View Related

Separate Data Stuff From Applications

Jan 22, 2007



Hi,

This is probably for most of you a very basic question. My goal is to define in a seperate instance from application all infos related to DataSets and DataAdapters that are needed when connecting to a specific database. Why?

First, I would like to be able to have in a single instance everything needed when hooking to a SQL Server Express database and in an other everything needed when hooking to a SQL Server CE database. Then, from application, I would like to be able following a few basic configuration steps to choose from one or the other, or even both in specific cases.

Second, I want to be able to seperate Database related stuff from application so that I can re-use everything from any other application when needed.

I've read several books, articles on the subject and would like to have your opinion as several approaches were illustrated through them. What would you use for this:

- Component class?

- Class library?

- or else?

Any good articles on the subject?



Thanks in advance for sharing,

Stéphane

View 3 Replies View Related

Transact SQL :: Query Using Stuff Keyword

Jun 17, 2015

CREATE TABLE BILL_DETAIL
([objid] int,[x_billable_to] varchar(19), [x_bill_quantity] int,
     [x_billable_yn] int, [x_bill_rate] int,   [COST_TYPE] varchar(19) )
INSERT INTO BILL_DETAIL
([objid], [x_billable_to], [x_bill_quantity], [x_billable_yn], [x_bill_rate],[COST_TYPE])

[code]...

how to get records using stuff keyword as above i want to query using where condition with where objid=1 and should frame output as Parking, Toll only 1 input parameter need to given.

View 20 Replies View Related

SQL CE 3.1 Connection String And Some Other Basic Stuff

Oct 9, 2007

Since I couldnt find an easy way to connect Orcas Beta 2 with SQL CE 3.1

I'll try by a connection string

since im totally new at this
does anyone have any idea how to get started?

Thxs!

View 4 Replies View Related

Merge Replication - Weird Stuff

May 21, 2007

I'm implementing merge replication between SQL CE and sql server 2005 SP2. Here is the problem I'm facing



I have dynamic filters on some tables like

Select * from table1 inner join table2

ON table1.field1 = table2.field3

and table2.flag = true



When table2 flag turns true then all the matching records in table1 should be returned to the subscriber.



But that is not happening. The filter does not return any records to the subscriber even though i see records when i run the query on the server. My take on this is the publisher thinks there is no changes on table1 so there is nothing to update. So to fix that i run dummy updates like

update table1

set [name] = [name]

where table1.field1 in

(Select field2 from table2 where flag=true)



This updates the records and the publisher updates the subscriber the first time. When i set the flag to false, it is supposed to remove the data from the subscriber but i get this error.




The merge process failed because it detected a mismatch between the replication metadata of the two replicas, such that some changes could be lost leading to non-convergence. This could be due to the subscriber not having synchronized within the retention period, or because of one of the replicas being restored to a backup older than retention period, or because of the publisher performing more aggressive cleanup on articles of type download-only and articles with partition_options = 3. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147199363)
Get help: http://help/MSSQL_REPL-2147199363

The common generation watermark is invalid at this replica since it does not exist or metadata for changes not yet propagated may have been cleaned up. (Source: MSSQLServer, Error number: 21800)
Get help: http://help/21800





I have no idea whats going on. Any clues, anyone? Thanks for your help.





Ramesh

View 13 Replies View Related

Renaming A Project... Some Minor Stuff

Apr 16, 2008

I have a project. Originally when I created this project, I called it "Project_A", (and I did not create a solution directory).

Doing this created a folder called "Project_A" with the following files within it. I guess these are meta data files and I shouldnt be messing around with them. Anyway, I see

(1) Package.dtsx (The default package that gets created with a new project)
(2) Project_A.database
(3) Project_A.dtproj
(4) Project_A.dtproj.user
(5) Project_A.sln
(6) Project_A.suo

When I rename my project in the Solution Explorer to "Project_B", the following happens in my folder.

Everything remains the same except Project_A.dtproj gets renamed to Project_B.dtproj and a new file called Project_B.dtproj.user gets created.

Now, my questions.

Question 1: What if I wanted my folder to have the same name as my project? Can I just change the folder name in Windows Explorer without having any ill-behaviors later on? I always have 1 project to 1 solution so I want to use the convention of keeping my folder named the same as my project.

Question 2: What about the files that are still named with Project_A dot blah blah. Is it bad if I renamed these to Project_B dot blah blah?



View 7 Replies View Related

VS Express Free For Good And Other Fun Stuff

Apr 19, 2006

A whole bunch of exciting new stuff announced around the Visual Studio Express Editions today. VS Express is now free for good, not just 1 year (just like SQL Server!). Also lots of great new content and fun projects to do.

See Dan Fernandez's blog posting at http://blogs.msdn.com/danielfe/archive/2006/04/19/579109.aspx for lots of details.

Best, MJ

View 1 Replies View Related

Partitioning Tables And Filegroup Stuff

Jan 17, 2007

Hi everyone,
 
Primary platform is 64-bit on A-P cluster.
 
Our needs are on yearly basis and on monthly basis. We're forced to keep up five years for the majority of the production tables.
In terms of years, I see three ways:
 
1.Create all the ranges for a FILEGROUP with a only NDF
 
2004, 2005, 2006 => FG1 =>  ONE.NDF
 
2.Create all the ranges for a FILEGROUP along with more than one NDF.
 
2004, 2005, 2006 => FG1 =>  ONE.NDF
                                                       TWO.NDF  
 
3.Create each range to a FILEGROUP where there will be  one NDF or  (n) NDF
 
2004 => FG0=> ZERO.NDF
2006 => FG1 => ONE.NDF
2005 => FG2 => TWO.NDF
 
What is the best approach in terms of availability, performance and best practices? Maybe is a silly question, I'm sorry if it is.
 
As usual, thanks a lot for your time.
 

View 3 Replies View Related

Splitting Digits And Alphabets..

May 14, 2008

is there any builtin functions or any other ways to split digit and numbers in sql server2005.
   for example in  Patel1234 , i am want to split patel and 1234 seperately.
                                    thanks,

View 5 Replies View Related

Decimal Rounding To 2 Digits

Feb 16, 2012

This give me 6 digits to the right of the decimal point - can round it to 2???

CONVERT (decimal(18 , 2), 1.0 * NULLIF (vVotesR, 0) / NULLIF (vVotesR + vVotesD, 0) * 100)

View 3 Replies View Related

Find Value 9 Digits In Length

Apr 17, 2008

Just looking for some guidance on how to find a value thats 9 digits in length

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved