none
String Limit > condition

    Question

  • 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???

    Thanks

    Ganesh

    Monday, April 9, 2018 1:41 PM

All replies

  • 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. 
    • Edited by Benjamin Kettner Tuesday, April 10, 2018 9:39 AM Please, just ignore, misread the question.
    Tuesday, April 10, 2018 9:36 AM
  • 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.

    Regards,

    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 MSDNFSF@microsoft.com.

    Tuesday, April 10, 2018 9:37 AM
    Moderator
  • 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
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Tuesday, April 10, 2018 10:06 AM