how to specify the column name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gobiparthi

    how to specify the column name

    Dear friends,

    If i want to specify the column name as "acc_no" then it
    total size is 6 it must get the first two letters as alphapets and the
    remaining 4 as numbers for this how to write the query?. Please reply.

    By,
    Gobi S.

  • Jack Vamvas

    #2
    Re: how to specify the column name

    what is the naming procedure i.e will you know what the letters and numbers
    will be .
    If you mean dynamically create the value then
    DECLARE @number INT
    SET @number = mynumber
    'aa_'+convert(v archar(4),@numb er)

    --
    ----
    Jack Vamvas
    _______________ _______________ _____
    Receive free SQL tips - www.ciquery.com/sqlserver.htm
    _______________ _______________ _____


    "gobiparthi " <gobi.sdce@gmai l.com> wrote in message
    news:1150186162 .136272.244460@ g10g2000cwb.goo glegroups.com.. .[color=blue]
    > Dear friends,
    >
    > If i want to specify the column name as "acc_no" then it
    > total size is 6 it must get the first two letters as alphapets and the
    > remaining 4 as numbers for this how to write the query?. Please reply.
    >
    > By,
    > Gobi S.
    >[/color]


    Comment

    • DickChristoph

      #3
      Re: how to specify the column name

      Hi Gobi

      Not sure if you meant how to define the table or query it But here is how
      you would define it.

      Create table accountnums(
      row_id int not null identity(1,1) Primary Key,
      acc_no varchar(6))

      alter table accountnums add CONSTRAINT CK_acc_no CHECK (acc_no LIKE
      '[A-Z][A-Z][0-9][0-9][0-9][0-9]')

      insert accountnums(acc _no) values('aa1234' ) --OK
      insert accountnums(acc _no) values('AA1234' ) -ok
      insert accountnums(acc _no) values('A11234' ) --Generates error.


      --
      -Dick Christoph

      "gobiparthi " <gobi.sdce@gmai l.com> wrote in message
      news:1150186162 .136272.244460@ g10g2000cwb.goo glegroups.com.. .[color=blue]
      > Dear friends,
      >
      > If i want to specify the column name as "acc_no" then it
      > total size is 6 it must get the first two letters as alphapets and the
      > remaining 4 as numbers for this how to write the query?. Please reply.
      >
      > By,
      > Gobi S.
      >[/color]


      Comment

      • Madhivanan

        #4
        Re: how to specify the column name

        Welcome to the website of Narayana Vyas Kondreddi. This is a personal website, with some technical stuff which you will find useful. This site features some great SQL Server, Visual Basic, ASP resources. You will also find an FAQ section on SQL Server replication. You will also find a list of handy shortcut keys of some Microsoft products. Additional sections include: A code library which features VB programs, stored procedures; A page dedicated to SQL Server related books;


        Madhivanan


        gobiparthi wrote:[color=blue]
        > Dear friends,
        >
        > If i want to specify the column name as "acc_no" then it
        > total size is 6 it must get the first two letters as alphapets and the
        > remaining 4 as numbers for this how to write the query?. Please reply.
        >
        > By,
        > Gobi S.[/color]

        Comment

        Working...