Avatar of Richiep86
Richiep86

asked on 

sql search as you type

select userid, (last_name + '; ' +first_name+' ['+UPPER(userid)+']') as appr_name from zusm_approvers where general_approver = 1 and userid not in ('%USER_ID%') and (last_name+';'+first_name like '%%%usersearchspec%%%' OR last_name+'; '+first_name like '%%%usersearchspec%%%' OR last_name+';'+first_name like '%%%usersearchspec%%%' OR last_name+','+first_name like '%%%usersearchspec%%%' OR first_name+';'+last_name like '%%%usersearchspec%%%' OR first_name+'+ SPACE(1)'+last_name like '%%%usersearchspec%%%' )  ORDER BY last_name,first_name

Open in new window


the above does not search by first_name SPACE last_name...

Customers should be able to type their first name followed by a space to search their name.

i have tried this:

OR first_name+'+ SPACE(1)'+last_name like '%%%usersearchspec%%%'
OR first_name+' '+last_name like '%%%usersearchspec%%%'

with no luck,

Any ideas?
Thanks
Microsoft SQL ServerMicrosoft SQL Server 2005Oracle Database

Avatar of undefined
Last Comment
Richiep86
ASKER CERTIFIED SOLUTION
Avatar of Saurabh Bhadauria
Saurabh Bhadauria
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Richiep86
Richiep86

ASKER

Great work!
Avatar of Richiep86
Richiep86

ASKER

Could you also tell me why the system auto-selects the first result returned?

If a user tries to search “smith”, the system defaults to arrowsmith as that’s the first result returned?

Is there anyway (editing the exisiting code) to stop the search auto selecting the first result?

Many thanks,
Avatar of Richiep86
Richiep86

ASKER

Do i need to ask another question? or can this be covered in the same thread?

many thanks.
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

That is due to the %'s

I.E search for smith

'%%%usersearchspec%%%'

will find *smith* (hence arrowsmith)

'usersearchspec%%%'

will find smith*
Avatar of Richiep86
Richiep86

ASKER

That is correct but why does it always select arrowsmith as default?

Thanks gav!
Avatar of gavsmith
gavsmith
Flag of United Kingdom of Great Britain and Northern Ireland image

Because you have

ORDER BY last_name,first_name

Open in new window


so therefore alphabetically arrowsmith comes before smith

Regards
Avatar of Richiep86
Richiep86

ASKER

doenst work if i use 'usersearchspec%%%'

cheers
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo