String Limit > condition


  • i have a "integer" datatype in one column also have a only one string data!!!

    how to set a limit like "columnname"<'String'....

    retreive all the row data before that string???



    lundi 9 avril 2018 13:41

Toutes les réponses

  • AFAIK you can not. 

    Explanation: The columns in a database are not ordered, which one is "before" the next can be changed by just modifying the order of the columns in your SELECT statemtent. This means that there is no natural order on the columns which in return means that you cannot do this. 

    What you could do (although honestly I am not sure if this really answers your question) is build a dynamic SQL statement, by composing a SQL string, querying the columns from the sys.columns table and comparing/ordering/filtering the result set to your liking and then executing the generated SQL statement with sp_executesql.

    Benjamin Kettner

    Aaah - sorry, just realized that I misread your questions. I thought that you wanted to select only columns based on the condition. My bad. 
    • Modifié Benjamin Kettner mardi 10 avril 2018 09:39 Please, just ignore, misread the question.
    mardi 10 avril 2018 09:36
  • Hi Ganesh pitchai,

    The less than is used to compare two expression. The expression is any valid expression, both expression must have implicitly convertible data types.

    See: <= (Less Than or Equal To) (Transact-SQL)

    In your scenario, how to make the query work depends on which type of your 'columnname'

    Assume it is a int type, you have to use CAST or Convert function before you do the comparison.

    For example:

    declare @test as table (item1 int, item2 varchar(20))
    insert into @test values (1,'a'),(2,'b'),(3,'c')
    select * from @test where Cast(item1 as varchar(20))<'b'

    Check if you need more help.


    Pirlo Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    mardi 10 avril 2018 09:37
  • sounds like what you're looking is this

    LEN(Columnname) >= LEN('yourstring')

    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    mardi 10 avril 2018 10:06