Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Substring issues

Posted on 2006-11-20
2
Medium Priority
?
379 Views
Last Modified: 2012-05-05
I have been trying to combine 2 fields together.  I have tried several different permutations of the substring command and am having no luck.  

I have defines all fields involved in this command as char.  Here is what I am trying:

insert
into lcs_out
substring('prefix,1,2)+substring(class_subject_cd,1,10)as Unique_id
from temp_table

this should be easy, but I am knocking my head against the wall.

any advice is appreciated.  

0
Comment
Question by:ericsberr
[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
2 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17981345
>I have been trying to combine 2 fields together.

possibly you want to update an existing table/field/row:
update temp_table
set lcs_out =  substring(prefix,1,2)+substring(class_subject_cd,1,10)

or update another table:
update lcs_out
set uniqueid=  substring(t.prefix,1,2)+substring(t.class_subject_cd,1,10)
from  lcs_out l
join temp_table t
  on <some join condition>

0
 
LVL 9

Accepted Solution

by:
gpompe earned 2000 total points
ID: 17981346
The syntax is fine, except you have a single quotation mark before "prefix"
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

604 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