SQL 2012 :: Leading Zeroes Substring Query In Server

Mar 16, 2015

Padding leading zeroes for the months in End date

Example: actual data is like

6222007
,11301998
in end date column the following query works fine for 11301998 and converts it as 19981130 which was correct.

But 6222007
fails because month has no leading zero and it converts it as 0076222 which is wrong.

How can i make it as 20070622 with the following code

select (case when replace (ltrim(rtrim(ltrim([end date]))), '|', '') in ('99999999','00000000') then NULL
else substring ([END DATE],5,4)+SUBSTRING([END DATE],1,2)+SUBSTRING([END DATE],3,2) end) as ConvEnd_date

from Mydatabase.dbo.[AccountTable]

View 3 Replies


ADVERTISEMENT

SQL Server 2012 :: Return Number With 2 Leading Zeroes

May 5, 2015

In a t-sql 2012 select statement, I have a query that looks like the following:

SELECT CAST(ROUND(SUM([ABSCNT]), 1) AS NUMERIC(24,1)) from table1. The field called [ABSCNT] is declared as a double. I would like to know how to return a number like 009.99 from the query. I would basically like to have the following:

1. 2 leading zeroes (basically I want 3 numbers displayed before the decimal point)

2. the number before the decimal point to always display even if the value is 0, and

3. and 2 digits after the decimal point.

View 3 Replies View Related

Csv And Leading Zeroes

Oct 4, 2006

I'm trying to write the contents of a csv file to a table, but I am having problems with fields with leading zeroes.  Whenever I save as csv I lose the leading zeroes.  Does anybody know how to prevent this?

View 1 Replies View Related

Remove Leading Zeroes And Keep Spaces

Sep 27, 2001

I have a char(12) field that was loaded like '000000000101' I need to change the data to be ' 101'. Is there a way to do this and preserve the number and keep the leading spaces?
Thanks

View 3 Replies View Related

Transact SQL :: Return Number With 2 Leading Zeroes

May 5, 2015

In a t-sql 2012 select statement, I have a query that looks like the following:

SELECT  CAST(ROUND(SUM([ABSCNT]), 1) AS NUMERIC(24,1)) from table1.

The field called [ABSCNT] is declared as a double. I would like to know how to return a number like 009.99 from the query. I would basically like to have the following:

1. 2 leading zeroes (basically I want 3 numbers displayed before the decimal point)
2. the number before the decimal point to always display even if the value is 0, and
3. 2 digits after the decimal point.

Thus can you show me the sql that I can use to meet my goal?

View 3 Replies View Related

Converting Int To Fixed Length Char With Leading Zeroes

May 25, 1999

Hello All,
Can someone tell me how (in SQL) to convert an integer to a fixed length character filled with leading zeros. For example, I have an integer value of '125'. My user wants to see it displayed as '00000125'. How do I get the zeroes to fill in to a char(8) field when the length of the value differs, ie. '1', '125', '3452', etc.

Thanks in advance,
Terry

View 1 Replies View Related

Integration Services :: SSIS Is Removing Leading Zeroes From 6 Character Time String?

May 29, 2015

I am using SSIS 2012 SP1 to import a comma delimited csv file into a SQL table.

One of the fields carries a time value:

Source = textfile, column=DT_STR(8), value format = "hhmmss", e.g. "011525"
Destination = field in SQL table, data type = time(0)

To get it from the textfile to the SQL table I am:

1.) Creating a derived column called [d_Time of Entry]with the following formula -

SUBSTRING([Time of Entry],1,2) + ":" + SUBSTRING([Time of Entry],3,2) + ":" + SUBSTRING([Time of Entry],5,2)

2.) Performing a data conversion task to convert [d_Time of Entry] from DT_STR(8) to time(0) The upload fails because values that start with a zero, i.e. times before 10am, have their leading 0's stripped before being derived.  You can see this because "011525" is derived as "11:52:5" when it should be "01:15:25".

View 10 Replies View Related

Transact SQL :: Use Print Function To Output Numeric Variable With Fixed Amount Of Leading Zeroes

Apr 23, 2015

I need to create an output from a T-SQL query that picks a numeric variable and uses the print function to output with leading zeroes if it is less than three characters long when converted to string.  For example if the variable is 12 the output should be 012 and if the variable is 3 the output should be 003.

Presently the syntax I am using is PRINT STR(@CLUSTER,3) .  But if @CLUSTER which is numeric is less than three characters I get spaces in front.

View 4 Replies View Related

SQL Server 2012 :: INT Or BIGINT With Leading Zeros

Nov 5, 2015

Looking at an execution plan the conversion of NVARCHAR(15) to BIGINT is a big yellow exclamation NO NO. However, the numbers in the NVARCHAR(15) have leading zeros.

Technically speak 0123456789 is not an INTEGER or BIGINT, the performance of my Stored Procs is there any way to allow leading zeros in a BIGINT Field?

View 5 Replies View Related

SQL Server 2012 :: Using Substring For A Destination Field?

Aug 23, 2014

I have a Function where I want to put a character in a particular position in a Destination string. For example, I have a 5 character field containing, say, "12345". I would like to put the letter "A" in the third position resulting in "12A45". I'm trying the following

DECLARE @RetVal as varchar(5)
SET SUBSTRING(@RetVal,3,1) = 'A'

I'm getting a compiler error

"incorrect syntax near '@RetVal'. Expecting '(' or SELECT"

Am I using the wrong Function to do this? If so, what should I be using?

View 2 Replies View Related

SQL 2012 :: Populate Number With Leading Zeros To Make It As 5 Digits

Jan 23, 2015

Logic:ensure the Docket number is 5 digits and populate with leading zeros if not.I have to check input number field is 5 digits, if not I have to populate with leading zeros to make it as 5 digits.

View 2 Replies View Related

SQL 2012 :: Retain Leading Zeros While Exporting SSRS Report To Excel

Jan 28, 2015

I have a query in a SSRSreport that returns a value that looks like '012345'. The value looks fine on the report preview screen.

When the report is exported to excel, that value is displayed in a cell as '012345'. When I click out of the field, excel is dropping the leading zero and converting the value in the field to 12345.

Why is this happening and i have converted the value as string as well using expression.

View 3 Replies View Related

Substring Query

Mar 5, 2008

name
--------------------------------------
copd_update_sept2007 9/25/2007 3:24:50 PM
copd_update_sept2007 9/26/2007 1:18:07 PM
feb2008_v2_n2 2/25/2008 1:56:41 PM
feb2008_v2_n2 2/26/2008 2:28:05 PM

i want string like till '' blank spaces..

how can i get that
select substring(name,1,15) from mymaxiddate

View 10 Replies View Related

Help With A Substring Query

Mar 20, 2006

I need help capturing information from a free text field.The 10 examples below contain examples of the information I am tryingto capture.In each cell I am trying to capture the number between 'TranID=' andthe next '&'.So in the fisrt cell I would like to capture 14078800.Things you will need to keep in mind are;The number is not of fixed length.'TranID' will always precede the numberThe number will always be followed by an '&'The '&' sign can occur multiple times in the text.Code=web.co.uk%product_250p&TranID=14078800&OtherFlag0=services.web.stats.PostContentDelivery&OtherFlag0par=delivCode=web.co.uk%product_free&TranID=14077576&OtherFlag0=services.web.stats.PostCSDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077583&OtherFlag0=services.web.stats.PostCSDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077584&OtherFlag0=services.web.stats.PostCSDelivery&OtherFlag0par=delivCode=web.co.uk%product_150p&TranID=14077579&OtherFlag0=services.web.stats.PostCSDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077603&OtherFlag0=services.web.stats.PostCSDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077741&OtherFlag0=services.web.stats.PostContentDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077757&OtherFlag0=services.web.stats.PostContentDelivery&OtherFlag0par=delivCode=web.co.uk%2Fpush_wallpaper_250p&TranID=14077770&OtherFlag0=services.web.stats.PostContentDelivery&OtherFlag0par=delivCode=web.co.uk%product_250p&TranID=14077604&OtherFlag0=services.web.stats.PostContentDelivery&OtherFlag0par=delivRegards,Ciarán

View 8 Replies View Related

Using Query Parameter When Data Cell Has Leading Spaces

Feb 21, 2008



In SQL Reporting I want the user to pass a parameter to the report; the parameter is a employee number. Easy right, you write a where statement like where table_name.employee_number =@employee_number. When the user runs the report they€™re asked to type in the number.

My problem is the dB stores the employee number with leading spaces padding the number out to 9, so if the user types in 1 they get jack, but if they type in €˜ 1€™ they get the right employee. I can€™t roll it out that way

I€™d do something in the where clause so the user could just type in 1 & it would auto pad out to 9 spaces. I€™ve tried using the €˜LIKE€™ clause & I€™ve tried using concatenate but so far neither works well.

I'd appreciate any advice

Thanks -- Vince

View 3 Replies View Related

Problem In Select Query, Substring

Oct 26, 2007

declare @s varchar(50)declare @t varchar(50)set @s='sandeep(hello)fees account'set @t=@sselect substring(                 @s,                 charindex('(',@s)+1,                 charindex(')',@s)                 )
 
What i wanted to get is the text in between '(' and the closing ')'   but when i tried the above statments iam not getting the right answer

View 1 Replies View Related

Query For Substring To Get Some Particular Value In A String (Get Querystring Value By Sql )

Jan 28, 2008

I have a column name URL in Table1 with data like  <a href="/Folder1/view_media_news.cfm?news_media_i=1">August 2002 Factsheet</a>            <a href="/Folder1/view_media_news.cfm?news_media_i=149">March 2002 Newsletter </a>  i need to grab the news_media_i value by sql query  Please any one can help me to get that particular value from string using substring or any other suggestion Thank you in advance 

View 4 Replies View Related

Error In Query; Invalid Length Parameter Passed To The Substring Function

Nov 28, 2005

Hi
i got errro mess "Invalid length parameter passed to the substring function" from this below. Anyone how can give me a hint what cause this, and how i can solve it? if i remove whats whitin thoose [] it works, i dont use [] in the code :)
colums:
VLF_InfectionDestination is nvarchar 254

SELECT TOP 10 tb_AVVirusLog.VLF_VirusName, COUNT(tb_AVVirusLog.VLF_VirusName) AS number
FROM tb_AVVirusLog INNER JOIN
__CustomerMachines002 ON tb_AVVirusLog.CLF_ComputerName = __CustomerMachines002.FalseName
WHERE (CONVERT(varchar, tb_AVVirusLog.CLF_LogGenerationTime, 120) BETWEEN @fyear + @fmonth + @fday AND @tyear + @tmonth + @tday) AND
(__CustomerMachines002.folder_id = @folderId) [OR
(CONVERT(varchar, tb_AVVirusLog.CLF_LogGenerationTime, 120) BETWEEN @fyear + @fmonth + @fday AND @tyear + @tmonth + @tday) AND
(tb_AVVirusLog.VLF_InfectionDestination LIKE N'%@%')]
GROUP BY tb_AVVirusLog.VLF_VirusName
HAVING (NOT (tb_AVVirusLog.VLF_VirusName LIKE N'cookie'))
ORDER BY COUNT(tb_AVVirusLog.VLF_VirusName) DESC

View 7 Replies View Related

SQL Server 2012 :: Adding Count To Query Without Duplicating Original Select Query

Aug 5, 2014

I have the following code.

SELECT _bvSerialMasterFull.SerialNumber, _bvSerialMasterFull.SNStockLink, _bvSerialMasterFull.SNDateLMove, _bvSerialMasterFull.CurrentLoc,
_bvSerialMasterFull.CurrentAccLink, _bvSerialMasterFull.StockCode, _bvSerialMasterFull.CurrentAccount, _bvSerialMasterFull.CurrentLocationDesc,
_bvSerialNumbersFull.SNTxDate, _bvSerialNumbersFull.SNTxReference, _bvSerialNumbersFull.SNTrCodeID, _bvSerialNumbersFull.SNTransType,
_bvSerialNumbersFull.SNWarehouseID, _bvSerialNumbersFull.TransAccount, _bvSerialNumbersFull.TransTypeDesc,

[code]...

However, as you can see, the original select query is run twice and joined together.What I was hoping for is this to be done in the original query without the need to duplicate the original query.

View 2 Replies View Related

SQL Server 2012 :: How To Pull Value Of Query And Not Value Of Variable When Query Using Select Top 1 Value From Table

Jun 26, 2015

how do I get the variables in the cursor, set statement, to NOT update the temp table with the value of the variable ? I want it to pull a date, not the column name stored in the variable...

create table #temptable (columname varchar(150), columnheader varchar(150), earliestdate varchar(120), mostrecentdate varchar(120))
insert into #temptable
SELECT ColumnName, headername, '', '' FROM eddsdbo.[ArtifactViewField] WHERE ItemListType = 'DateTime' AND ArtifactTypeID = 10
--column name
declare @cname varchar(30)

[code]...

View 4 Replies View Related

Preappending Zeroes

Apr 13, 2006

Hi ,

Sorry for those that think this is obvious but I have tried for good time and cannot solve this problem in a simple way.

How can I append a 0 in the form of varchar to a 1 with datatype integer

What Im trying to do is add an alternate column to the identity column in my table.

The identityt collumn seeds in 0 all the way up with increments of 1.
ie 0,1,2,...,n
howver, I need that for the values below 10 a zero is preapended
ie
01,02,03,...,09, and then the sequence continues normally, ie 10,11,...,n. I am trying to preapend the zeroes to the mentioned dinumbers in the new calculated column I created without success.
this is what I would like tot do
select IdentityCoulmn,('0'+ IdentityCoulmn) as CalculatedCoulumn
from MyTable

but its not working the result comes out the same ie 1,2..n

thank you

View 8 Replies View Related

Padding Zeroes To An Int

Jan 18, 2008

Hi,

I need a simpler way of doing this:

I've a number column which I need to show as a 3 digit field in a string:
Example:
number =1; string = 010
number =10; string =100

is there any function that can do this string manipulation?


Currently I'm using a CASE statement to check the length of this number column,
if its single digit I use:
SUBSTRING(('0' + CONVERT(VARCHAR,CONVERT(INT,ISNULL(D.Number,E.Number)))+'0'),1,3)

else I use
CONVERT(VARCHAR,CONVERT(INT,ISNULL(D.Number,E.Number)))+'0')

Is there a better way of doing this?

Thanks,
Subha

View 5 Replies View Related

If Not Numeric Change To Zeroes.

Sep 27, 2007

Hello,
I'm new to sql, currently I am creating sql queries for work, I was wondering if anyone can help me.

Field Name: Telephone
If, for example: abcdefghij was entered in the Telephone field, I want it change into 0000000000 and when an actual telephone# is entered, 4165559999 I want it to be displayed under the Telephone field.

Greatly appreciated.

View 2 Replies View Related

Pad Zeroes To Source Column

Oct 6, 2015

I am having one table with 1 column DCID which is a bigint.

DCID column have data like 1,12,123

My Requirement is to Pad zeroes to

DCID to make 5 characters.

View 4 Replies View Related

Maintain Leading Zeros When Exporting To .csv Using SQL Server 2000 DTS

Jan 13, 2008

I am trying to export the result of a select into a .csv file using SQL Server 2000 DTS. The data for varchar fields has leading zeroes in the database, which is very much required in the csv file.

But, the .csv file trims the leading zeroes. How do we force to maintain the same data as in source?

I had used Text File Destination Connection as the destination, with the below options
File Extension: .csv
File Format: Delimited
File Type: ANSI
Text Qualifier: Double Quotes ("")
Row Delimiter: {CR}{LF}
Column Delimiter: comma

Source Data: 0123
Target Data (Requirement): 0123

The data in .csv: 123 (This is the issue)

When I open this file in a Text Editor, I do see the data in double quotes..."0123".

Thanks in advance.

View 6 Replies View Related

SSIS Leading Zeros Gone After Migration Of Mainframe To SQL Server

May 22, 2007

I am migrating mainframe data to SQL Server 2005 and have found that from a mainframe character field with leading zeros for example the value of 00023 to a SQL Server column defined as varchar (5) the resulting column value is 23 not 00023. I need the leading zeros because these are account ids, etc. So the value is 00023 not 23. Is this some setting in SQL Server 2005 that needs to be changed or what? This is not a numeric field on the mainframe or a numeric column for SQL Server.

View 11 Replies View Related

Getting Rid Of Trailing Zeroes From A Decimal Output

Feb 1, 2006

HiI use SqlServer 2000I am doing a select and sending the results, which is a cast() intodecimal (9,3), in an email to various other users of our system.Problem is that a number like 95.2 is display as 95.200. Is there anyway I can trim it so that it will display 95.2 ?David

View 1 Replies View Related

Remove Trailing Zeroes From Result Set

Jan 31, 2008



I have a column of type Decimal(14, 4) in my SQL server 2005 database.
When producing the result set on this column, i need to convert the values to varchar datatype and also i do not want the trailing zeroes to be displayed.
For eg:
If the value stored is 98.7500, my select query should provide an output of 98.75.
Similarly if the value stored is 98.0000, my select query should output 98.

I tried converting the value to "float" and then assigning to varchar data, however doing so i am incurring precision loss in some scenarios
See below:


Declare @ele as varchar(25)

Select @ele = Convert(float, 99999.9990)

select @ele


Output I received: 100000
Output I wanted: 99999.999
Are there any in-built functions in SQL to achieve what I need?

View 4 Replies View Related

SQL Server Agent SSIS Job: Set Values Drops Leading Quote

Jul 19, 2006

We are using BCP in a Process task. The value for the path to BCP's error log requires double quotes around it. We initially put this value in a configuration file, and that worked fine. Yesterday, we eliminated the config file and tried to use the "Set Values" tab of the SSIS SQL Server Agent job to pass in this value.

The package variable was assigned the value of the path -- all except for the leading double quote. The closing quotation mark was included in the value.

We tried adding a second double quote at the beginning of the value, but that caused the job to fail immediately.

For now we will work around this problem by putting the quotes around the value in a Script task inside the package.

Has anyone else encountered this problem?

Thanks,

Ron

View 2 Replies View Related

SQL Server 2008 :: Substring Date To DD/MM/YYYY

May 7, 2015

I have a field called Period which stores a date range, i.e '01/01/15 - 20/01/15'

I can convert the first part into a start_date using:

substring(m.customer_order_no,1,2)+ '/' +substring(m.customer_order_no,4,2)+ '/' +substring(m.customer_order_no,7,2) as 'start_date'

However I want to put into date format as '01/01/2015', I am trying below but it keeps it as '01/01/15'

convert(varchar(10),substring(m.customer_order_no,1,2)+ '/' +substring(m.customer_order_no,4,2)+ '/' +substring(m.customer_order_no,7,2),103) as 'start_date'

View 9 Replies View Related

SQL Server 2012 :: Query To Get Min Value

Feb 7, 2014

Below is what I have so far Also I am getting other FRID besides 0 as well.

Select P.PartID, P.mansPart, P.Cost As PartCost, V.PartID, V.PartNo, V.price As VendPrice, M.title, C.CoName, P.FRID
From Parts As P
Right Join Vend2Part As V
On P.PartID = V.PartID And P.FRID = V.FRID
Left Join companies As C

[Code] ....

View 4 Replies View Related

SQL Server 2012 :: Query To Return Top 10 Tables On Each Database On Server?

Nov 21, 2013

i need a query to return the top 10 tables in each database on a server. have used EXEC sp_msforeachtable 'sp_spaceused ''?''' which returns what I need for one db but I need it to loop through and gather the info for all dbs on server. maybe need cursor not sure. for reporting reasons i would like to include the name of the server and name of database.

View 3 Replies View Related

SQL Server 2012 :: Add Total To Query

Dec 18, 2013

I have a table with the Group name and Total Count by group . I need to add a 'Total' and summation of all counts at the end .

CREATE TABLE #TempTable
(GroupName VARCHAR(10),NumberOfCases INT
INSERT INTO #Temp Table (GroupName,NumberOfCases)
VALUES ('Grp A',10)
INSERT INTO #Temp Table (GroupName,NumberOfCases)
VALUES ('Grp B',20)

[code]....

View 5 Replies View Related







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