Left or Length Command | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Left or Length Command

I have a field that contains data such as ‘ACB00/02’. How would I write into a function that gathers a load of data together for me a peice of code that will grab only the first 2 chars of the afore mentioned value, So the result would be in the new created colum in a temp table ‘AC’. This is to occur over 7,000 records but they are not all AC, I just want the first two from every line. Regards
Toni Chaffin
aka Toni
As this is about to run on onyl 7k rows, it shouldn’t make a big difference if you use LEFT(<column>, 2) or SUBSTRING(<column>,1,2).
You don’t need a UDF for this. A straight
INSERT INTO <temp table> SELECT SUBSTRING(<column>,1,2) FROM <original table> should do the job —
Frank Kalis
Microsoft SQL Server MVP
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)