Tuesday, March 27, 2012

Convert 1st letter to uppercase in SQL comand

Hi all!
This is the problem:
User enters student name, in the database, only the 1st letter is uppercase and the rest is in Lower case.
So, I want to fix this so as it is not case sensitive, i.e. the user can enter a name and it will return the record
whether they enter it in upper or lower case.
My Code:
CvtUpperCase.Text = UCase(Content.Text) //stores user's input

Select Case OptionChoice

Case "Student_FirstName"
MyCommand = New SqlDataAdapter("select * from [qryStudentDetails] where [qryStudentDetails].[Student_FirstName] like
'" & CvtUpperCase.Text & "'" , myConnection)

...
Any ideas??

User the T-SQL UPPER() function:
select * from [qryStudentDetails] where UPPER([qryStudentDetails].[Student_FirstName]) like '" & CvtUpperCase.Text & "'"
[edit]
By the way... I don't think text comparissons in SQL are case sensitive at all? I could be wrong though...
[/edit]|||Excellent!! Thank you so much! Was jammed on that for ages!

No comments:

Post a Comment