Hello all this is my first post.
I am trying to strip some unwanted text from a column containing department names.
This first query strips all characters after the colon in the name: - SELECT
-
CASE WHEN CHARINDEX(':', DB.Table.DEPT)>0
-
THEN
-
LEFT(DB.Table.DEPT, CHARINDEX(':', DB.Table.DEPT)-1)
-
ELSE
-
DB.Table.DEPT
-
END
-
FROM
-
DB.Table
The second query strips the prefix from the name: - SELECT
-
REPLACE(
-
REPLACE(
-
REPLACE (DB.Table.DEPT,'[NA1] ','')
-
,'[NA2] ', '')
-
,'[NA3] ', '')
-
FROM
-
DB.Table
Both of these work great independent of each other, but when I try to combine them it fails. - SELECT
-
CASE WHEN CHARINDEX(':', DB.Table.DEPT)>0
-
THEN
-
LEFT(DB.Table.DEPT, CHARINDEX(':', DB.Table.DEPT)-1)
-
ELSE
-
DB.Table.DEPT
-
END
-
FROM
-
(SELECT
-
REPLACE(
-
REPLACE(
-
REPLACE (DB.Table.DEPT,'[NA1] ','')
-
,'[NA2] ', '')
-
,'[NA3] ', '')
-
FROM
-
DB.Table)
I could really use some guidance with this.
Thanks in advance.
2 1276
Please use code tags when posting code or formatted data.
The problem with your combined query is that you never give the expression you created an alias. You also didn't alias your subquery.
With what Rabbit said try something like -
SELECT
-
CASE WHEN CHARINDEX(':', A.DEPT)>0
-
THEN
-
LEFT(A.DEPT, CHARINDEX(':', A.DEPT)-1)
-
ELSE
-
A.DEPT
-
END
-
FROM
-
(SELECT
-
REPLACE( REPLACE( REPLACE (DB.Table.DEPT,'[NA1] ','') ,'[NA2] ', '') ,'[NA3] ', '') as DEPT
-
FROM
-
DB.Table) A
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nick Heppleston |
last post by:
I have a concatenation problem and I was wondering if somebody might be
able to offer some help :-)
I have the following table structure holding product long descriptions:
Part...
|
by: pb648174 |
last post by:
I have a single update statement that updates the same column multiple
times in the same update statement. Basically i have a column that
looks like .1.2.3.4. which are id references that need to...
|
by: christopher.secord |
last post by:
Is there any advantage to doing this:
ALTER TABLE testtable ADD
CONSTRAINT PK_sysUser
PRIMARY KEY NONCLUSTERED (UserID)
WITH FILLFACTOR = 100,
CONSTRAINT IX_sysUser
UNIQUE NONCLUSTERED...
|
by: Krish |
last post by:
I have created 2 tables, both tables have the same column names (property
ColumnName) it is priceDate,priceTime and priceValue
I get an error saying that Column priceDate already belongs to...
|
by: Marina |
last post by:
Hi,
Let's say I bind the same column to multiple properties of one control (or
even to the same property of several controls).
If a user changes the value of the property in one control - I...
|
by: Asfar |
last post by:
I have a databound column in DataGridView.
Is there a way to have different cell types in the same column?
Thanks,
-Asfar
|
by: Volition |
last post by:
I have looked around and can't find any help for my SQL problem.
I have a Table which lists people
peopledb.
_____________
id | Name
1 | Fred
2 | Bill
3 | Bob
|
by: pl1 |
last post by:
Hi everyone,
I'm using MS-Access 2003, OS: Window XP Professional sp3.
In Northwind database (sample Database),the Suppliers table have column "SupplierID" which is also present in Products...
|
by: perhapscwk |
last post by:
vba, how to use vba to search how many distinct amount in same column?
for example..
column C have amount
123
123
444
123
445
|
by: spmartin2012 |
last post by:
I'm sure this is very simple, but I'm just starting with these types of tasks. I need to copy a cell value to the same column in the next row and cycle thru all data. I can use this twice to do...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |