?
Solved

Sql query in vb.net project.

Posted on 2006-04-17
5
Medium Priority
?
175 Views
Last Modified: 2010-04-23
I need to get the fristname and lastname  from the ownername1 field.  I know it is something like this but I'm not sure how to incorporate this in the query.  I tried but I keep getting sql errors:

(SELECT     LEFT([ownername1], CHARINDEX(',', [ownername1]) - 1) LastName,
     SUBSTRING([ownername1], CHARINDEX(',', [ownername1]) + 1, LEN([ownername1])) FirstName

 If source = "PROPERTYTAX" Then
                'Need to get lastname and frist and last name from ownername field
                MySQL = "Select ownerename1 as firstname, ownername1 as lastname, locationaddress as address, locationcity as city, locationzip as zip from " & source & " where ownername1 =  " & firstname
            End If

Thank you for your help.
0
Comment
Question by:running32
  • 2
  • 2
5 Comments
 
LVL 34

Expert Comment

by:Brian Crowe
ID: 16475500
You might be better off parsing the name field on the client side instead of in the query.  You might be running into errors in the case that there is no comma in the field which would give you a zero length for the LEFT function.
0
 
LVL 3

Accepted Solution

by:
PierreBeukes earned 2000 total points
ID: 16476395
Hi, I ran this query against my db... and it works - gives me the LastName and Firstname in 2 fields.


SELECT LEFT([ownername1], CHARINDEX(',', [ownername1]) - 1) LastName,
SUBSTRING([ownername1], CHARINDEX(',', [ownername1]) + 1, LEN([ownername1])) FirstName From TestTable


What are you trying here?

If source = "PROPERTYTAX" Then
'Need to get lastname and frist and last name from ownername field

MySQL = "Select ownerename1 as firstname, ownername1 as lastname, locationaddress as address, locationcity as city, locationzip as zip from " & source & " where ownername1 = " & firstname

You can go

MySQL = "Select SUBSTRING([ownername1], CHARINDEX(',', [ownername1]) + 1, LEN([ownername1])) as firstname, LEFT([ownername1], CHARINDEX(',', [ownername1]) - 1) as lastname, locationaddress as address, locationcity as city, locationzip as zip from " & source & " where SUBSTRING([ownername1], CHARINDEX(',', [ownername1]) + 1, LEN([ownername1])) = " & firstname From TestTable


End If

Hope that helps.
0
 

Author Comment

by:running32
ID: 16477516
I get the error IErrorInfo.GetDescription failed on the above query  
0
 
LVL 3

Expert Comment

by:PierreBeukes
ID: 16477757
Im still not exactly sure what you are trying to do?

Can you give more detail?
0
 

Author Comment

by:running32
ID: 16480004
worked it out.  Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

830 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