stuartmarsh Posted December 7, 2009 Share Posted December 7, 2009 Hi All, I don't know if this is simple or not, but I'd like some SQL to return a number of sequential values starting at a number I specify. For example, I want to start at 5 for 5 iterations. The result I would like back would be Numbers 5 6 7 8 9 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/184311-t-sql-to-get-numbers-between-1-and-n/ Share on other sites More sharing options...
corbin Posted December 7, 2009 Share Posted December 7, 2009 Hrmmm... Why do you want to do this? Why not just use what ever language you're pulling the data into? If you're trying to select things between something, you can do WHERE x >= 5 AND x < 10 (not sure if MSSQL has BETWEEN or not). Quote Link to comment https://forums.phpfreaks.com/topic/184311-t-sql-to-get-numbers-between-1-and-n/#findComment-973069 Share on other sites More sharing options...
stuartmarsh Posted December 7, 2009 Author Share Posted December 7, 2009 I have some SQL that gets the current week number based on today's date I.e 200940. Based on that I want to get the last n weeks, so ultimately I have a SQL that gives me WeekNo 200940 200939 200938 200937 I could do this with a loop in PHP but I'm trying to do it in the SQL if possible. Quote Link to comment https://forums.phpfreaks.com/topic/184311-t-sql-to-get-numbers-between-1-and-n/#findComment-973103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.