Solved

Sql server query syntax left() function

Posted on 2013-10-22
2
223 Views
Last Modified: 2013-10-22
My goal:  Select all records from table Part_Serial_Number, column Part_No,  where the first character of Part_No = "P" and create a new table PS_Serial_Number with those records.

My current query fails with "Invalid column name "P":

SELECT Part_No
INTO PS_Serial_Number
FROM  Part_Serial_Number
WHERE (LEFT(Part_Serial_Number.Part_No,1)) = "P"

Part_No is type nvarchar

I know this must be obvious, but I'm floundering...

Thanks,
Brooks
0
Comment
Question by:gbnorton
2 Comments
 
LVL 16

Accepted Solution

by:
DcpKing earned 500 total points
ID: 39591003
select *
from Part_Serial_Number
into PS_Serial_Number
where len(Part_No) >= 1
and substring(Part_No, 1, 1) = 'P'

(Strings are delimited by ticks, not quotes!)

hth

Mike
0
 

Author Closing Comment

by:gbnorton
ID: 39591079
Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

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