Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Extracting Substring into New field

Author  Topic 

Harold01
Starting Member

1 Post

Posted - 2007-12-20 : 12:45:41
I am trying to populate two fields in my table with the first 6 characters in an existing field with the following command:

SELECT dimension_elist,
SUBSTRING(dimension_elist FROM 1 FOR 6)
AS BU_Number
SUBSTRING(dimension_jde_pl FROM 1 FOR 6)
AS Acct_Number
FROM JDE_Import

The result is an error:
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.

I am fairly new to SQL so I am probably missing something basic.

Does anyone have any thoughts?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-20 : 12:48:08
You can use LEFT(dimension_elist,6) & LEFT(dimension_jde_pl,6)

OR SUBSTRING(dimension_elist,1,6)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-21 : 01:28:12
quote:
Originally posted by Harold01

I am trying to populate two fields in my table with the first 6 characters in an existing field with the following command:

SELECT dimension_elist,
SUBSTRING(dimension_elist FROM 1 FOR 6)
AS BU_Number
SUBSTRING(dimension_jde_pl FROM 1 FOR 6)
AS Acct_Number
FROM JDE_Import

The result is an error:
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.

I am fairly new to SQL so I am probably missing something basic.

Does anyone have any thoughts?


Did you know SQL Server has help file where you can find some examples?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -