-2

In my EditText I want to enter the first character as alpha and the remaining is whatever. I achieved this task with the help of TextWatcher. But now my problem is if I entered something wrong(like digits, special characters) as my First character then my EditText shouldn't accept the remaining characters. If I correct my first character then only my EditText should accept. Is their any possibility to achieve this friends? If yes then please guide me friends.

My textWatcher code is

edittext.addTextChangedListener(new TextWatcher() {

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        if (s.length() > 0) {
            String str = edittext.getText().toString();
            char t = str.charAt(0);
            if (!Character.isLetter(t)) {
                Toast.makeText(getApplicationContext(),
                        "please enter your first charecter as alpha",
                        Toast.LENGTH_LONG).show();
            }
        }
    }
});

Thanks in advance.

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
  • 1
    We need a better description of your problem. What does it mean "*in table itself*"? Are you asking about `SELECT` query to find duplicates? – PM 77-1 Apr 10 '13 at 07:23
  • What is the desired output that you are looking for? Do you want to select those that has duplicates, or those that has unique? – Mahmoud Gamal Apr 10 '13 at 07:25
  • @praveen your Query will work for only one Column of value...For Ex: i want to insert more than one Developer in Department But Could not allow More than One Head/Department.... – Gunaseelan Apr 10 '13 at 07:28

2 Answers2

3
CREATE UNIQUE INDEX ON UnnamedTable (Department) WHERE Designation='Head'

It's called a Filtered Index. If you're on a pre-2008 version of SQL Server, you can implement a poor-mans equivalent of a filtered index using an indexed view:

CREATE VIEW UnnamedView
WITH SCHEMABINDING
AS
    SELECT Department From UnnamedSchema.UnnamedTable WHERE Designation='Head'
GO
CREATE UNIQUE INDEX ON UnnamedView (Department)
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
1

Execute the following query to view duplicates:

Select Department,Designation,count(*) 
From [mytable] Group by Department,Designation

Now replace mytable with the table name and department and designation with the columns in the table. After execution the result set will show a count of more than one for duplicate records.

asim-ishaq
  • 2,190
  • 5
  • 32
  • 55