SQL Server 2012 :: Remove String From Column Post Code Field

Sep 8, 2015

I am querying with a SELECT statement against an address table that has a post code column with corrupt data.

Sample record:- Northants NN4 0NB
Should be NN4 0NB

I have used the following on another column:-

LEFT(A.Addr1,CASE WHEN CHARINDEX ('(', A.Addr1) =0 THEN LEN(A.Addr1) ELSE CHARINDEX('(' ,A.Addr1) -1 END) AS 'Address 1'

but unable to correct this problem?

View 9 Replies


ADVERTISEMENT

SQL Server 2012 :: Finding Longest String Within A String Field

Mar 20, 2014

We have some URLs within a bulk block of text some of which are very long. I need to identify rows where such urls exceed say 100 characters in length in amongst other text.So the rule would be return a record if within the string there is a string (without spaces) longer than 100 characters.

View 9 Replies View Related

SQL Server 2012 :: Select Case Statement To Remove Part Of String After One Or Two Specific Characters

Jun 3, 2015

I have an Address column that I need to Substring. I want to remove part of the string after either, or both of the following characters i.e ',' OR '*'

Example Record 1. Elland **REQUIRES BOOKING IN***
Example Record 2. Theale, Nr Reading, Berkshire
Example Record 3. Stockport

How do I achieve this in a CASE Statement?

The following two case statements return the correct results, but I some how need to combine them into a single Statement?

,LEFT(Address ,CASE WHEN CHARINDEX(',',Address) =0
THEN LEN(Address )
ELSE CHARINDEX(',' ,Address ) -1 END) AS 'Town Test'

,LEFT(Address ,CASE WHEN CHARINDEX('*',Address ) =0
THEN LEN(Address)
ELSE CHARINDEX('*' ,Address ) -1 END) AS 'Town Test2'

View 8 Replies View Related

SQL Server 2012 :: Remove Non Alpha Chars From A Column

Mar 1, 2014

How to remove non alpha chars from a column ?

I googled the following code
Create Function [dbo].[RemoveNonAlphaCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin

[code]....

View 9 Replies View Related

SQL Server 2012 :: Remove CR-LF In Between Column Which Is Text Datatype?

May 1, 2015

I have a column A as 'text' datatype. This has CR-LF in between data.How to remove it.

I am trying to copy result from SQL to Excel

Eg:
A CR LF
ABC CR LF
DVB CR LF

The output should be:

A
ABC DVB

View 2 Replies View Related

Remove A Comment String From Text Field

Oct 24, 2007

I have a field that contains some text. Each field will have none or atleast one comment in it. A comment can be a string of any length with *** on both sides. Ex: ***comment***


Declare @Test_tbl Table(TextField Text)
Insert Into @Test_tbl
Select 'Some text ***comment*** some more text' Union all
Select 'Other text ***another comment*** more and more text' Union all
Select '***Comment*** some text ***More Comments***' Union all
Select 'some text with no comment'


I need the output be ...

TextField
--------------
Some text some more text
Other text more and more text
some text
some text with no comment




Thanks in advance.

View 4 Replies View Related

SQL Server 2012 :: Insert Empty String In A Decimal Field?

Jul 13, 2015

I have a requirement where i have to insert empty string in column whose datatype is decimal.

I have to replace the column value if it is null then insert it as ' '.

Obviously its generate error msg for conversion, is there any workaround for this. I cannot add 0 or other value as this column is used to generate some output value.

IIF(Column1 IS NULL, ' ', Column1))

I used TRY_PARSE but it insert null value if there is conversion error.

View 3 Replies View Related

SQL Server 2012 :: Find A Specific String And Replace It With Another Inside Of VARCHAR Field

Aug 14, 2015

I'm trying to find a specific string (a name) and replace it with another inside of a VARCHAR(7000) field. Unfortunately, there are names like Ted and Ken that I'm trying to replace. I would like to leave words like Broken, admitted, etc... intact.

UPDATEtbl
SETBody = LEFT(REPLACE(tbl.Body, pm.OldFirstName, p.FirstName), 7000)
FROM Table tbl
JOIN Person p ON p.PersonID = tbl.PersonID
JOIN PersonMap pm ON pm.PersonID = p.PersonID AND LEN(pm.OldFirstName) > 2
WHEREtbl.Body LIKE '%[^a-z]'+pm.OldFirstName+'[., ]%

'The problem I'm running into is that the '[, ]%' in the LIKE excludes any record that ends with the FirstName because it is requiring either a space, comma or period after the name. Is there some way to add an empty string to the list of acceptable characters as that would cover any scenario in the data? I would prefer not to add all characters except space, comma and period, but I guess I could do that.

View 5 Replies View Related

SQL Server 2012 :: Getting String Out Of Data From A Column?

May 7, 2015

I have system id information in table system_ids and productids and systemidinsformation has lot of data but I am looking two strings in tire data to pull into two separate columns. details below

Database versions :ms sql 2008/2012
tablename:system_id's
column:system id information

sample data from system_id_information column

########################################
<obj xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:vim25" versionId="5.5" xsi:type="ArrayOfHostSystemIdentificationInfo"><HostSystemIdentificationInfo xsi:type="HostSystemIdentificationInfo"><identifierValue> unknown</identifierValue><identifierType><label>Asset Tag</label><summary>Asset tag of the system</summary><key>AssetTag</key></identifierType>

[Code] .....

I am looking output of two columns, which are bolded

product_id snumber
654081-B21 MXQ43905SW

for serial number this is common

before string :HostSystemIdentificationInfo"><identifierValue>

and after string </identifierValue><identifierType><label>Service tag

and snumber is always between the before and after string and number of characters of snumber varies and entire data for a row also varies

View 9 Replies View Related

T-SQL (SS2K8) :: How To Remove Special Characters From Column Value In A String

May 16, 2015

I want to remove special characters from a string in sql like <?> in a column value in a table.

View 1 Replies View Related

SQL Server 2012 :: String Format To Be Formed Out Of A Column

Nov 3, 2015

I am trying to find a solution to get the result set to fetch a particular string format from a table in my database, which has a column of NVARCHAR data type

CREATE TABLE #ActivityComments(Comments NVARCHAR(MAX))

INSERT INTO #ActivityComments VALUES('This is the study code for Field Phase S14-04932-01')
INSERT INTO #ActivityComments VALUES('Phase reporting has the study S15-04931-01 which is obselete')
INSERT INTO #ActivityComments VALUES('Phase running study code S14-04932-02 is not valid')

The output of the query should be like:

S14-04932-01
S15-04931-01
S14-04932-02

Is there any way possible to achieve this..

View 7 Replies View Related

SQL Server 2012 :: Record Count Of Column Field

Oct 30, 2014

I have created table in which there are four columns (id, date, parcelname, parcelnumber) and 10 rows. I want to count record of the column parcelnumber but condition that, in between two different dates the record should be counted.

View 9 Replies View Related

SQL 2012 :: Remove Character From Specific Column

Nov 18, 2014

How to remove Character From Column,Just Character. I want to work with number.

View 4 Replies View Related

How Can U Remove My Post ? Data Migration From AS400 To Sql2005

Apr 17, 2007

Hi,

Yesterday I had posted a query of How to transfer the Data from AS400 files to Sql 2005 tables with DTS and the error I received for the same. I am not able to view the replies since it has been deleted. Pls repost the same. I posted the query expecting for a solution but instead my question was deleted..... the very purpose of forum is defeated.



Regds,

Anu

View 4 Replies View Related

Extrach Part Of A Column String Into Another Field

Feb 6, 2001

hi, I have a field named city_state that contains city and state together (Warren, OH) in the same field. I need to create two seperate columns one city, another state. how can I extract the state out of the city_state column and have two different column.
thanks

Ahmed

View 2 Replies View Related

Code To Post Files To A SharePoint Site

Feb 13, 2008

I am looking for sql code/approach to export a text file and 2 excel works sheets(from an excel workbook) in a folder, to 3 different tables in sql server, perform data scrubbing and then export the data from all 3 tables to 3 different excel sheets and post them in 3 different web parts in a share point site.

Mainly sql code(or any code that i can integrate with SQL Server) to post files to different web parts in a share point site is what i am looking for.

Any sort of pointers/suggestions would be really helpful.

Thanks & Regards,

View 4 Replies View Related

Integration Services :: SSIS 2012 Lookup Transform Converts Date Field To String

Jul 30, 2015

We are using lookup transformation in SSIS 2012. The lookup transformation queries a table with two date columns. When we hover the mouse over the two columns in the 'columns' tab of the lookup transformation editor, the two columns show as DT_WSTR instead of DT_DBDATE. This causes the SSIS package to fail due to data type mismatch.A similar abandoned thread is available at: URL....

View 2 Replies View Related

Join Returns More Than One Row, Post Code Regular Expressions

Mar 23, 2006

Hi,I trying to write a select statement that will return each of my salesmen a region code based on a table of post codes using wildcards... eg.MK1 1AA would be matched in the region code table to MK1%SELECT dn.DEALER_CODE, dn.NAME AS DNAME, rc.REGION_ID,rc.POST_CODE, dn.POSTAL_CODEFROM REGIONAL_CODES rc CROSS JOINDEALER_NAW dnWHERE (dn.POSTAL_CODE LIKE rc.POST_CODE)The above statement works BUT there are some post code areas such asour friends in Milton Keynes that are split into two regions... eg MK1is region id 2 and MK10 is region 3.So a dealer with post code MK10 1AA would be matched to both rowsreturning duplicatesPOST_CODE REGION_IDMK1% 2MK10% 3I think the answer would lie in a subquery which returns the ID of theregion with the longest length of the postcode match (e.g.len(POST_CODE) for the rc table... return only the MAX....any ideas????Any help muchos appreciated, and I apologies now for the naming of thedealers name as a reserve word... not me!Ct

View 2 Replies View Related

How To Remove Non-Numeric Or Non-alphameric Characters From A String In Sql Server 2005

May 16, 2007

Hi to all,
I am having a string like  (234) 522-4342.
i have to remove the non numeric characters from the above string.
Please help me in this regards.
Thanks in advance.
M.ArulMani
 
 

View 2 Replies View Related

How To Remove Non-Numeric Or Non-alphameric Characters From A String In Sql Server 2005

May 16, 2007

Hi to all,
I am having a string like  (234) 522-4342.
i have to remove the non numeric characters from the above string.
Please help me in this regards.
Thanks in advance.
M.ArulMani
 
 

View 2 Replies View Related

SQL Server 2008 :: Remove Double Quote In String Fields

Feb 23, 2015

I have a SQL select syntax as below

0 AS SalaryMin,
2088 AS SalaryMax,
2088 AS BillableHours,
'Month' AS SalaryPaidCode,
0 AS SalaryBreakdownHourly,
0 AS SalaryBreakdownDaily,

[Code] ...

While outputting to CSV.file

I got :0,2088,2088,"Month",0,0,0,0,0,0,0,"N/A","N/A","G","N/A","Exempt","Other",1

How can I remove all double quotes in the string fields? so that O can get the result as below while the output
0,2088,2088,Month,0,0,0,0,0,0,0,N/A,N/A,G,N/A,Exempt,Other,1

View 7 Replies View Related

SQL Server 2012 :: Remove First And Last Char

Jun 5, 2015

How to remove first and Last character from below select query.

SELECT LTRIM(RTRIM(REPLACE(col_1,'Year_',''))),
FROM Years

View 3 Replies View Related

SQL 2012 :: Matching Column IDs Based On Field Contents

Apr 2, 2015

I have tables in my database, tblNames1, tblNames2, tblNames3, and a main addresses table (currently empty). Once I've imported the address data I need to match the addressIDs in the names tables to the Primary ID in the address table based on the values of a field CompanyName (which is common to all the tables) My issue is that I have a huge CSV file with the master address information but obviously SQL server needs to assign foreign keys so the names tables can linked to corresponding rows in address table. It's a a many to 1 relationship as their will be one address with multiple name entries. All the names are normalized so everything can be matched up...

View 9 Replies View Related

SQL 2012 :: Populate Int Column With A Sequence Of Numbers But Sorted By Another Field

Oct 8, 2015

The following works just fine. The table tmpMHPCLMDET does have a column ADMTDT ( varchar(8) ).

While I am adding the sequence of numbers I like it to be sorted based on ADMTDT column.

What that means is the row with the earliest ( smallest ) ADMTDT will get 1 and the next 2 and so on.

Declare @ID int
If Exists ( Select c.name from sys.columns c where object_id = object_id('tmpMHPCLMDET') and C.name = 'ServiceLineID' )
Begin
--Adding a sequence of numbers to the ServiceLineID column.
SET @id = 0
UPDATE tmpMHPCLMDET
SET @id = ServiceLineID = @id + 1;
End;

View 2 Replies View Related

How Do I Post The ' Character Into A LongText Data Field?

Nov 22, 2005

I need to update the string in a longtext field. NewString = "This is a 'test'"

I can't figure out how to use an escape character to identify the string with " ' " and then also include the " ' " character inside the string.

Can anybody help me?

Thanks,

Alex

View 5 Replies View Related

SQL Server 2012 :: Function To Remove Excess Characters

Mar 5, 2014

I am looking for a function or way to return only results which does not include appended characters to order numbers.

For instance, below is a list of order numbers. I only want the order number that is SO-123456

OrderNumbers
SO-123456
SO-123456-01
SO-123456-2
SO-123457
SO-123457-1
SO-123457-02
SO-123458

I would like my query to only show the below results

SO-123456
SO-123457
SO-123458

What functions or query methods could achieve this?

I was hoping for something similar to RTRIM but that is only specific to white space.

View 9 Replies View Related

SQL Server 2012 :: CTE To Remove Overlaps And Produce Result

Aug 7, 2014

I am having problems building a CTE. I have a table:

declare @tbl table ( ID int, S time(0), E time(0) )

with the following data:

insert@tbl ( ID, S, E )
values ( 1, '03:00', '05:00' ),
( 1, '04:00', '06:30' ),
( 1, '22:00', '23:00' ),
( 1, '23:00', '23:40' ),
( 1, '23:30', '23:45' )

I need to build a CTE that will eliminate overlaps and produce the following result:

ID S E
-- --------- ---------
1 03:00:00 06:30:00
1 22:00:00 23:45:00

View 1 Replies View Related

SQL Server 2012 :: Remove Unwanted P/L Transaction Lines?

Aug 20, 2015

I am creating a report query that returns all unreconciled P/O lines. I am near completion but I am unable to find a way to remove the reconciled records.

I have included a script to produce some sample table, data & query.

The recordset dispalys 6 rows. All reconciled Supplier Invoices are duplicated and have transaction codes 40, 50 and reconcile code of 9 (5024, 921689471).

All unreconciled only appear once and have transaction codes 40 and reconcile code of 0 (4835 & 921978016). These are the only records that I want to show.

CREATE TABLE [dbo].[Purch_Ledger](
[EPDIVI] [nvarchar](3) NULL,
[EPSUNO] [nvarchar](10) NULL,
[EPSINO] [nvarchar](24) NULL,
[EPDUDT] [numeric](8, 0) NULL,
[EPTRCD] [numeric](2, 0) NULL,

[code].....

Whatever I try I cant find a way to get rid of the unwanted records.

View 3 Replies View Related

How Do I Post The Currentdatetime (now) Into A DateTime Field In SQLserver Using A Formview?

Feb 27, 2006

How do I post the currentdatetime (now) into a DateTime field in SQLserver using a formview? I tried a couple different techniques, but had problems with both:
1. TRY ONE: I created a date time field on the SQL server named entrydate. I can not figure out how to post the current datetime into it, without the user inputting it into a field.
 
2. Second TRY: I tried to change the datetime field on the sql server to a datetime stamp field, but it puts in a binary value. Then I can't read it correctly, and my delete functions don't work.
 
Thanks Ed

View 2 Replies View Related

SQL Server 2012 :: Stored Procedure To Remove All Records That Don't Have Max FileID

Jan 6, 2014

I have a SQL 2012 database that has 10 tables. One of the tables is populated by manual import from CSV file. Each time a user calls custom ASP.NET code., records get inserted into a table called forecast_data with incremental increase in FileID. So first import has FileID of 1, second import has FileID of 2 etc.

Structure:

TABLE [dbo].[forecast_data](
[recID] [bigint] IDENTITY(1,1) NOT NULL,
[FileID] [int] NULL,
[Project_Name] [nvarchar](255) NULL,
[Stoplight_Status] [nvarchar](255) NULL,
[Country] [nvarchar](255) NULL,
[Region] [nvarchar](255) NULL,

[code]....

What I am trying to do is only keep the data that has the highest FileID (MAX(FileID). I would like to write a store procedure that removes all older data once a new import is written into the table.

View 6 Replies View Related

SQL Server 2012 :: How To Remove Next And Previous Record Amount Equal To 0

Jun 2, 2014

Having below data. SHCOMP (Customer ID), CBLNAM ( Customer name), SHDESC (service description), SHAMT (service charge), SHTYPE (F-> From T-> To)

CREATE TABLE #Temp(
[SHCOMP] [numeric](7, 0) NOT NULL,
[SHDESC] [char](35) NOT NULL,
[SHTYPE] [char](1) NOT NULL,
[SHAMT] [numeric](9, 2) NOT NULL,

[Code] ....

I need to remove records that have the same ID, Name, Description and Amount summary = 0, For example

SHCOMP CBLNAM SHDESC SHAMT SHTYPE

123 cust1 desc1 45 F remove
123 cust1 desc1 -45 T remove
123 cust1 desc1 45 F remove
123 cust1 desc1 -45 T remove
123 cust1 desc1 45 F

[Code] ....

Results

SHCOMP CBLNAM SHDESC SHAMT SHTYPE

123 cust1 desc1 45 F

123 cust1 desc1 -35 T

234 cust3 desc2 30 F

here is what I did but didn't work because sum is <> from 0 so is leaving all records

select SHCUST, SHDESC, ABS(SHAMT) SHAMT
into #t1
FROM #Temp
group by SHCUST, SHDESC, ABS(SHAMT)
having SUM(SHAMT)=0
order by SHCUST

delete S from #Temp S
join #t1 T on T.SHCUST = S.SHCUST and T.SHDESC = S.SHDESC

View 5 Replies View Related

SQL Server 2012 :: Remove Named Instance From Failover Cluster

Oct 13, 2014

In QA we have a two-node cluster with four instances of sql. In trying to add a fifth, I was given an IP address already in use so the install hung.

I removed it from the cluster but it is still there in the registry etc on the node I was working on.

I read about using the maintenance tab of the sql server install to "remove a node" but the terminology is confusing. To me a node is a physical server and an instance is an instance of sql server -- not the same at all but they are often referred to as the same thing.

I definitely don't want to remove one of the servers from the cluster.

View 1 Replies View Related

SQL Server 2012 :: Remove Some Database Updates From Transaction Scope?

Mar 4, 2015

I have a stored procedure that does the following

BEGIN TRANSACTION OUTERTXN

BEGIN TRANSACTION
Copy records from live to archive
END TRANSACTION with commit or rollback
execute sproc to write audit log with success or fail
IF transaction was committed
BEGIN TRANSACTION
Delete records from live the archive
END TRANSACTION with commit or rollback
execute sproc to write audit log with success or fail
End IF

END TRANSACTION OUTERTXN with commit if both inner transactions were successful or rollback if either failed

If either inner transaction rolled back execute sproc to write audit log saying whole process is rolling back End IfMy problem is that if the outer transaction rolls back then I am losing the two audit records because they are part of the transaction scope. I want these executes to commit even if the master transaction fails.

View 2 Replies View Related







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