Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. MS-SQL Server querry question

MS-SQL Server querry question

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    ZGelic
    wrote on last edited by
    #1

    In table i have column that is type of varchar(n), and it's not primary/foreign key. Now, what I need is SQL query (stored procedure) that will select all the records in that table like: (pseudo) select * from table1 where SUBSTRING(table1.column2,1,2)<@param1 and SUBSTRING(table1.column2,1,2)>@param2 Parameters are first two letters of any record that contains data for that column. if param1 is aa and param2 is cc then output should be all the records with first two letters like: aa,ab,ac,...,az,ba,..,bz,ca,cb,cc Any suggestions would be appreciated!

    P S 2 Replies Last reply
    0
    • Z ZGelic

      In table i have column that is type of varchar(n), and it's not primary/foreign key. Now, what I need is SQL query (stored procedure) that will select all the records in that table like: (pseudo) select * from table1 where SUBSTRING(table1.column2,1,2)<@param1 and SUBSTRING(table1.column2,1,2)>@param2 Parameters are first two letters of any record that contains data for that column. if param1 is aa and param2 is cc then output should be all the records with first two letters like: aa,ab,ac,...,az,ba,..,bz,ca,cb,cc Any suggestions would be appreciated!

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      First off, I think you have your signs backward. Other than that, have you tried it?

      Z 1 Reply Last reply
      0
      • P PIEBALDconsult

        First off, I think you have your signs backward. Other than that, have you tried it?

        Z Offline
        Z Offline
        ZGelic
        wrote on last edited by
        #3

        Already solved and you're right, in solution that is similar to pseudo code I posted, the signs were backward... but it was just a hint for possible solution that someone could offer. Thanks for your comment anyway, cheers

        1 Reply Last reply
        0
        • Z ZGelic

          In table i have column that is type of varchar(n), and it's not primary/foreign key. Now, what I need is SQL query (stored procedure) that will select all the records in that table like: (pseudo) select * from table1 where SUBSTRING(table1.column2,1,2)<@param1 and SUBSTRING(table1.column2,1,2)>@param2 Parameters are first two letters of any record that contains data for that column. if param1 is aa and param2 is cc then output should be all the records with first two letters like: aa,ab,ac,...,az,ba,..,bz,ca,cb,cc Any suggestions would be appreciated!

          S Offline
          S Offline
          sri080188
          wrote on last edited by
          #4

          select * from table1 where SUBSTRING(table1.column2,1,2) like '%@param1%' or SUBSTRING(table1.column2,1,2)>'%@param2%' use dynamic query

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups