Showing posts with label names. Show all posts
Showing posts with label names. Show all posts

Wednesday, March 21, 2012

Plz solve this Query

chiranjeevi
raveendra
sreenivasarao
koteswar
manoj
sangeetharanika

Here my query is
in the above names i want to find out the persons whoz names consist of exact 2 a's
eg output:
raveendra

assume that the names are ename and table name is emp.

Thanks in advance
Plz mail this qury to chiru_y2k@.yahoo.com

ChiranjeeviOriginally posted by chiru_y2k
chiranjeevi
raveendra
sreenivasarao
koteswar
manoj
sangeetharanika

Here my query is
in the above names i want to find out the persons whoz names consist of exact 2 a's
eg output:
raveendra

assume that the names are ename and table name is emp.

Thanks in advance
Plz mail this qury to chiru_y2k@.yahoo.com

Chiranjeevi


select * from emp where patindex('%a%',ename) =2|||Borowing a page from Brett here...

select ename
from emp
where len(replace(ename, 'a', '') + 2 = len(ename)

Saturday, February 25, 2012

Please help...how to automatically generate names in the table?

Hello! every one, I am a student studying DB Admin and my professor gave us an assignment which I couldn' t quite get it. Could any one offer a hand?

the assignment is to generate random number with random name(female or male) the names are all from an imported table(such as one from Northwind).

He said first step was to decide on sex, then get the "count" of names, and then decide on ranmdom number between 1 and the count....

any way I am really confused and couldn't know how to start it.please help!

If your intention is to fetch the random name from the given table the followint query will do..

Code Snippet

Declare @.Sex as Varchar(10);

Set @.Sex='M'

Select Top 1 FirstName + ', ' + LastNamefrom Employees Where Sex=@.Sex Order By newid()