• enriquezreyjoseph (9/24/2013)


    AndrewSQLDBA (9/24/2013)


    Well, you can either search the table for one, or both.

    SELECT

    <ColumnName>

    , <ColumnName>

    FROM

    <TableName>

    WHERE

    Sex = 'M' OR SEX = 'F'

    That will select all rows with either M or F in the Sex column.

    If you want only one.

    SELECT

    <ColumnName>

    , <ColumnName>

    FROM

    <TableName>

    WHERE

    Sex = 'M'

    If you are using a sproc, simply add an input parameter with the SexyType

    And the query would be

    SELECT

    <ColumnName>

    , <ColumnName>

    FROM

    <TableName>

    WHERE

    Sex = @SexType

    Have you looked at the SQL Books Online for anything? This would be the place to start.

    And as almost everyone on here has stated, stop using Dynamic SQL.

    Andrew SQLDBA

    Hi Andrew 🙂

    But some post say that..Dynamic Sql is a powerful tool...

    can you give me a strong justification why should i stop using dynamic SQL?? PLEASE :-(..badly need some advise..

    1. Debugging a dynamic query is awful.

    2. risk of SQL Injection.

    3. when you have a very simple solution available for sex search, then why go dynamic 🙂