?
Solved

Left substring in Sybase

Posted on 2006-06-27
7
Medium Priority
?
1,173 Views
Last Modified: 2012-08-13
I have data in a column that is declared as varchar(20) and the data looks as follows:   123456.pdf
The number of characters before the .pdf can range from 6-10, so I need to grab all data to the left of the period.
I want to put this data into a new column in a different table truncating the ".pdf" part of the string.

My question is basically this:  How do I truncate the data to the left of the .pdf?
0
Comment
Question by:jmp02008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 14

Expert Comment

by:sathyagiri
ID: 16994679
In ORACLE it would be

 select substr('123456.pdf',1,instr('123456.pdf','.pdf') -1 ) from <tname>

Not sure if SYBASE has a INSTR function
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 16994879
SELECT  LEFT(MyField, LENGTH(MyField)-4)
FROM MyTableName
0
 

Author Comment

by:jmp02008
ID: 16995091
Ok this is what I got to work, but I'm getting an error when trying to insert it into a new table.

insert into table2 select substring(column_name, 1, charindex('.', column_name)-1) from table1

The table's are identical with respect to column name, type, and size.  But this is my error:
Msg 213, Level 16, State 4
Insert error: column name or number of supplied values does not match table definition.

any suggestions?



I can't use Left because I don't know the length of the string, it could be anywhere between 6-10 characters.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 38

Expert Comment

by:Jim P.
ID: 16995295
insert into table2 (column_name)
select substring(column_name, 1, charindex('.', column_name)-1) from table1


 LENGTH(MyField)-4 <-- If you know they will end in .pdf this will determine the length of the string and take off the last 4 characters.
0
 
LVL 25

Expert Comment

by:jrb1
ID: 16996310
How many columns in your tables? If more than one, you should have

insert into table2 (col1, col2, col3)
select substring(column_name, 1, charindex('.', column_name)-1), col2, col3
from table1
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 2000 total points
ID: 16996600
jrb1,

http://www.experts-exchange.com/Databases/Q_21900951.html#16995091

At the above post you can see that the Asker is only working on one column and I addressed it in my follow up post to that.

0
 
LVL 38

Expert Comment

by:Jim P.
ID: 17002812
Glad to be of assistance. May all your days get brighter and brighter.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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