Solved

Duplicate + trim records SQL

Posted on 2016-09-08
11
61 Views
Last Modified: 2016-09-08
Hi!
I have a sql and want 1 of the columns to return as 2 equal columns but one of them to be trimed. Is it possible?
Lets say you write "select files from images" and want the output to be "image1.jpg" in one of the columns and "image1" in the other.
0
Comment
Question by:Adam_Li
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 500 total points
ID: 41789710
so, this?

select files, replace(files, '.jpg', '') as filesnoext from images

Open in new window

0
 

Author Closing Comment

by:Adam_Li
ID: 41789741
Quick answear! This works very well. Thanks
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41789749
Are you looking for this

SELECT File, REPLACE(File, '.jpg', '') FileName from images

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41789750
Great !
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 41789752
You're welcome :)
0
 
LVL 32

Expert Comment

by:awking00
ID: 41789877
You might have also used -
select files, left(files,len(files) - 4) as name from images
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41789883
This will not work if your extension length is more than 3. E.g. jpeg
0
 
LVL 32

Expert Comment

by:awking00
ID: 41790105
And the accepted answer wouldn't work if the extension was .jpeg (or any other extension) either :-)
0
 
LVL 32

Expert Comment

by:awking00
ID: 41790111
Probably the safest way is to find the index of the ." and take the substring up until that index.
0
 
LVL 32

Expert Comment

by:awking00
ID: 41790113
... of the "." ...
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41790591
@awking00 - Yes you are correct. I have a solution for this.

@Author - if your extension can vary then use below rather than the accepted solution. To handle this you are can declare a variable and accept a value in there.

DECLARE @Ext AS VARCHAR(10) = '.jpg'

SELECT File, REPLACE(File, @Ext, '') FileName from images

Open in new window


Also please update the accepted solution.

Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question