How can I set range value in number in sql server

Hello,
I am using sql server 2012. I  want to display range value in int column. Suppose I have a table which contains
 columns called ID and dueDays. In dueDays there is data from 1 to 255 and slab range is 
[7,15,30,60,150,250].
Now I want to display range as per duedays, suppose from 1 to 7 , it should display 7.
1-7   =
 7
8-15  = 
15
16-60  = 60
61-150  =150
151-   151-250  =250
>250 = >250
Here is code snippet for create table and insert record.
Create Table Tmp
ID int ,
DueDays int
GO
DECLARE @I INT = 1
WHILE @I <=255
BEGIN
INSERT INTO TMP VALUES (@I,@I)
SET @I=@I +1
END
Please also see attached image of required result.
Prem Shah

hello Jingyan,
Thanks for reply but it doen't work in all case suppose range value is not exists in tmp then it is not working.
delete following record and check expected result is wrong .
delete from tmp where id in (3,7,15,30,60,150,250)
Prem Shah
Here is updated version:
Create Table Tmp ( ID int , DueDays int)
GO
DECLARE @I INT = 1
WHILE @I <=255
BEGIN
INSERT INTO TMP VALUES (@I,@I)
SET @I=@I +1
END
delete from tmp where id in (3,7,15,30,60,150,250)
--select * From Tmp
declare @range varchar(100)='3,7,15,30,60,150,250'
;with mySplit as (
SELECT distinct S.a.value('.', 'VARCHAR(100)') AS splitVal
FROM
(SELECT CAST (N'<H><r>' + REPLACE(@range, ',', '</r><r>')+ '</r></H>' AS XML) AS [vals] ) d
CROSS APPLY d.[vals].nodes('/H/r') S(a)
,mycte as (
SELECT a.id, iSNULL(a.id,splitVal) id2, splitVal FROM tmp a
full outer JOIN mySplit as s ON Cast(splitVal as int)=a.DueDays)
--select * from mycte
Select id, ISNULL(rng ,255) rangeValues from mycte m
outer APPLY (SELECT TOP 1 splitVal FROM mycte
WHERE id2 >= m.id2 AND splitVal IS NOT NULL
ORDER BY id2 ) d( rng)
WHERE id is not null
Order by id
drop table tmp

Similar Messages

  • How can I set a value of column in SSIS by using Replace

    How can I set a value of a column in SSIS using a Replace in Derive columns. I have here NameCode and I need to Set = 1 Where NameCode like LIKE '____99____'
    eg. 1006993010... if 5th and 6th characters are 99
    Else 0
    Hope to hear from someone soon and I appreciate great help here.

    If NameCode column is integer then you have to cast it correctly to String.
    I am adding that to the expression provided by Rajen.
    SUBSTRING((DT_WSTR,20)ProductCode,5,2) == "99" ? 1 : 0
    -Vaibhav Chaudhari

  • How can I set the value to a session bean from backing bean

    Hi Experts,
    How can I set the value to a session bean from backing bean where I have created getter and setter
    methods for that variable.
    Basically I am using ADFUtils class where I am able to get the value from session bean
    using following expression
    String claimType =
    (String)ADFUtil.invokeEL("#{ClaimValueObj.getClaimType}");
    Thanks
    Gayaz

    Gayaz,
    Wrong Post !!
    Post in JDeveloper and ADF
    Thanks
    --Anil                                                                                                                                                                                                                               

  • How can I set default values for Allocate Mode in AO config?

    Hi, How can I set default values for allocate mode in AO config. To be specific, in the attached vi, I need to set the Allocate Mode in AO Config to 'Use FIFO Memory (6)' if the value inside my case structure is false and to 'no change (0)' if the value inside the case strusture is true.
    Solved!
    Go to Solution.
    Attachments:
    generateWaveformFIFO.vi ‏15 KB

    Create two constants for the Allocate Mode input (right click > create > constant). Place one in the true case of the case structure, and place the other one in the false case. Wire them to the same tunnel (border of the case structure), then wire the tunnel to the Allocate Mode terminal of the AO Config. I don't have Traditional DAQ installed, but that should do it.
    Misha

  • How can i Set ArrayList values to selectOneListbox

    Please Let me know How can i Set ArrayList values to selectOneListbox dynamically from the managed bean

    Note: beanList is a list of selectItems
    ArrayList<SelectItem> beanList;

  • How can I set it to delete messages off my server after they download?

    How can I set it to delete messages off my server after they download?

    IMAP email is server based. The messages stay on the server and just view them remotely with an email client like Thunderbird. If you want to keep a copy on your computer you need to move a copy of the email message to a folder under Local Folders. If you delete the message off the server, it is going to be gone otherwise.
    The delete from the server option is a POP email server. It does not apply with IMAP email.

  • How can I set firefox as default browser in citrix server, only for few groups. does -silent -setdefaultbrowser option working in latest version?

    How can I set firefox as default browser in citrix server, only for few groups. does -silent -setdefaultbrowser option working in latest version?

    I think so: [http://discussions.citrix.com/topic/330585-firefox-default-browser-for-all-users/]
    Can you also set the default programs in the Group Policy User Settings?
    Reference: [http://community.spiceworks.com/topic/884740-default-user-profile-in-citrix-environment]

  • How can I make sure that in RAM our sql server is not facing any mermory crunch issue?

    The SQL server process always show RAM is highly used while its a default behaviour of sql server.
    How can I make sure that in RAM our sql server is not facing any mermory crunch issue?
    Thanks

    The SQL server process always show RAM is highly used while its a default behaviour of sql server.
    How can I make sure that in RAM our sql server is not facing any mermory crunch issue?
    Thanks
    The best way to make sure you are not facing memory pressure is to use perfmon counters and monitor various memory counters
    For SQL Server 2005 - 2008 r2 use below counters
    SQLServer:Buffer Manager--Buffer Cache hit ratio(BCHR): IIf your BCHR is high 90 to 100 Then it points to fact that You don't have memory pressure. Keep in mind that suppose somebody runs a query which request large amount of pages in that
    case momentarily BCHR might come down to 60 or 70 may be less but that does not means it is a memory pressure it means your query requires large memory and will take it. After that query completes you will see BCHR risiing again
    SQLServer:Buffer Manager--Page Life Expectancy(PLE): PLE shows for how long page remain in buffer pool. The longer it stays the better it is. Its common misconception to take 300 as a baseline for PLE.   But it is not,I read it from
    Jonathan Kehayias book( troubleshooting SQL Server) that this value was baseline when SQL Server was of 2000 version and max RAM one could see was from 4-6 G. Now with 200G or RAM coming into picture this value is not correct. He also gave the formula( tentative)
    how to calculate it. Take the base counter value of 300 presented by most resources, and then determine a multiple of this value based on the configured buffer cache size, which is the 'max server memory' sp_ configure option in SQL Server, divided by 4 GB.
      So, for a server with 32 GB allocated to the buffer pool, the PLE value should be at least (32/4)*300 = 2400. So far this has done good to me so I would recommend you to use it.  
    SQLServer:Buffer Manager--CheckpointPages/sec: Checkpoint pages /sec counter is important to know about memory pressure because if buffer cache is low then lots of new pages needs to be brought into and flushed out from buffer pool, 
    due to load checkpoint's work will increase and will start flushing out dirty pages very frequently. If this counter is high then your SQL Server buffer pool is not able to cope up with requests coming and we need to increase it by increasing buffer pool memory
    or by increasing physical RAM and then making adequate changes in Buffer pool size. Technically this value should be low if you are looking at line graph in perfmon this value should always touch base for stable system.  
    SQLServer:Buffer Manager--Freepages: This value should not be less you always want to see high value for it.  
    SQLServer:Memory Manager--Memory Grants Pending: If you see
    memory grants pending in buffer pool your server is facing SQL Server memory crunch and increasing memory would be a good idea. For memory grants please read this article: 
    SQLServer:memory Manager--Target Server Memory: This is amount of memory SQL Server is trying to acquire.
    SQLServer:memory Manager--Total Server memory This is current memory SQL Server has acquired.
       8.  Free List Stalls/sec – Number of requests per second that had to wait for a free page
       9. Free Pages – Total number of pages on all free lists (free lists track all of the pages in the buffer pool that are not currently allocate to a data page, and are therefore available for usage immediately)
    NOTE: If you have NUMA system don't use PLE to monitor memory condition it wont give correct value
    From 2012 Onwards
    Memory management has become easy from 2012 onwards as
    Max server memory also allocated memory for requests which require memory >8KB
    SQLServer:Memory Manager:Free Memory (KB)
    SQLServer:Memory Manager:Target Server Memory (KB)
    SQLServer:Memory Manager:Total Server Memory (KB)
    For NUMA system its also wort monitoring each node.
    Object - SQLServer:Memory Node:Total Node Memory
      (KB)
    Object - SQLServer:Memory Node:Target Node Memory
      (KB)
    Object - SQLServer:Memory Node:Free Node Memory
      (KB)
    Ideally if target server memory is less than or equal to total server memory there wont be memory pressure if target is > total it does not always means its memory pressure
    BCHR would also give you good idea about memory pressure
    If memory grants pending is frequently non zero there is memory pressure
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • How can i make iphone mobile website,  database in Sql Server 2005 ?

    how can i make iphone mobile website,  database in Sql Server 2005 ?
    Thanks & Regards
    Jamshed Ali
    Email id: [email protected]

    You need to be a little clearer in what you're asking.
    You can't make any web site in SQL Server - it's a database engine, not a website tool.
    What you can do is create web sites that pull data from a back-end SQL Server, but the SQL server doesn't handle the client connection at all (that's handled by a web server such as Apache, IIS, or similar).
    There are many ways to build such a site including .NET, PHP, Perl and more (although I don't know all the options for Windows servers because they're not as common outside of corporate/enterprise networks).
    In either case, given your choice of development language (HTML, plus one of the PHP/Perl/.NET/etc. options), plus your database (SQL Server) plus your web server (IIS, Apache, etc.) you can make any web site you like (or, at least, you're capable of developing).
    If you want to opimize that web site for iPhones then there are many references on how mobile browsing differs from the desktop. I'd recommend this book as a reference (and, yes, I understand the irony of linking to a paperback book for web design guidance ). Googling mobile web design (or iPhone web design) might yield more results.

  • How can I set a value in a field before create when a New button is clicked

    Hi,
    I am using
    JDeveloper 10.1.3.1.0.3984 and
    JHeadstart 10.1.3.1 release 10.1.3.1.26
    I have one group and there is a detail group under that group.
    From main group to detail group there are 3 field relating those groups.
    field1
    field2
    fieldSEQ (auto-generated by database trigger)
    These 3 fields are PK.
    In the detail group, there is a New button. So, when the New button is clicked, it tries to create the record with those 3 fields value as those are coming from main group. As a result it's giving the duplicate error as that record already exists in the table.
    But I don't want to create the record with that SEQ as that will be created in the trigger.
    How can I set the SEQ temporarily any no. (-1) before create when the New button is clicked?
    Can anybody help?
    Thanks
    Syed Jabbar
    University of Windsor
    Windsor, ON, Canada

    Hello Syad,
    What I would suggest is setting the sequence number at the creation of the entity object (so in the create() method) by using the database sequence. This way it will always be unique.
    So something like:
    protected void create(AttributeList AttributeList) {
    super.create(AttributeList);
    SequenceImpl sequence =
    new SequenceImpl("KCP_SEQ", getDBTransaction());
    setFieldSeq( sequence.getSequenceNumber());
    If this still does not solve it: please go to the ADF Forum since this problem is an ADF problem, not a JHeadstart problem.
    Regards,
    Evert-Jan de Bruin
    JHeadstart Team.

  • How can i set up my Skype Number

    Can i set up my skype number to be accessible in two skype accounts and if the other skype account is not available it call gets diverted to another skype account?

    Note: when I click on South Korea, takes me to a page informs me there are special requirements for South Korean Skype numbers. However, when I click on "Next" to verify I am a resident of Korea, it informs me of technical difficulties. Is any one else getting this error?

  • How can i set the values to text box by selecting from drop down list.

    hi ,
    i am using struts and jsps. i have a dropdown list of names(getting the values of names from database), i want to get address and phone number of that selected one.how can i get that?

    Hi swarupa,
    Well My advice in this senario wud Be
    Either U can make Use of XmlHttp Object through javascript(AJAX way).
    Or U need to Maintain the State of the entire form and then refresh the page to get those results....
    just for U r reference i am attaching a link which was programmed using ASP @ server side and which made use of XmlHttp Object.....
    http://www.w3schools.com/ajax/ajax_database.asp
    Just try to simulate the samething in your own way....
    REGARDS,
    RAHUL

  • How can I set the Computer Serial Number as a Variable?

    Hey everyone, need some help here,  I need to get some data from a workstation using a script.  What I would like to do is "echo" the serial number of the workstation to certain spots in the data file.  The only way I know how to
    do this is by setting the serial number as a variable and doing a echo %SERIALNUMBER%.
    How can I do this?
    I found the WMIC key:
    wmic bios get serialnumber
    doesn't help much though.

    Hi usgrcm,
    What is your current situation?
    Will the scripts suggested by Frederik Long work here to meet your needs?
    Besides, regarding scripts issue, if any further help needed, we could also ask in Microsoft Scripting Guys forum:
    The Official Scripting Guys forum!
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    Best regards
    Michael Shao
    TechNet Community Support

  • How can I set default value to a transient parameter  in the VO

    I have created a transient parameter in the VO, which is type of boolean.
    When I try to input the "true" or "True" or "Y" in the 'default value',
    and then running the programm, but all failure.
    so I don't know how can i do.
    Genuinely waiting for you help, thanks in advance.

    Hi Sumury,
    First of all you could check if this transient attribute is read only. to check this, edit the VO and select the transient attribute under the Attributes tab. Then verify if it is marked as "Updateable Always" on the right-hand section.
    If it is updateable, then try setting the default value on the VO Implementation class: open the xxxVOImpl class, go to the transient attribute's setter (setxxx()) and change it to:
    <code> if (getXXX() == null) setAttributeInternal(XXX, "Y");
    else setAttributeInternal(XXX, value);</code>
    This might work. If it does not, then please post the exact message you are receiving when running the app.
    Hope this helps!
    Thiago

  • How can we set default value within html:file

    Hai,
    To set default value to text box i use the following code. It works well.
    <html:text property="modifyserverdesc" value="<%= serverDesc%>" styleClass="text" size="38"/>But for file i use the code
    <html:file styleClass="file" property="modifyserverimgfile" value="<%= serverImage%>" size="40"/>It doesn't display value. What is problem here?

    Hi,
    guess that one option in a RowImpl would be to check if the attribute is null or if the attribute value can be found in the VO that populates the list. If first is true or seconds false (cannot be found) you return the first value of the VO, making it the current attribute value
    Frank

Maybe you are looking for

  • How can I put Desktop 1 to my macbook and Desktop 2 on LCD screen?

    Hello. I have a problem. I would like to use some of my programs on Desktop 1, and other on my Desktop 2 for example not just to put browser to LCD screen. Is that possile or am I asking for too much? Thank's. [I'm new to apple world]

  • HT201210 Ipod Touch Screen has nothing on it and cant turn it off.

    My son's Ipod Touch has a blue/purple screen and will not respond at all when trying to turn off. The screen is blank and also will not let me restore it on the computer when I try.

  • Final Delivery checkbox/indicator in SRM

    Hello Experts, We are using SRM 5.0 connected to an ECC 6.0 system using Extended Classic Scenario. How exactly is the "Final delivery" checkbox activated in the backend? I don't see any box in SRM by this name... I only find the following at the Ite

  • How to support chinese gb2312 in XML Document?

    the Doc of oracle xml parser said as below,where to get the doc ? Please help me. ======================================== The parser currently supports the following encodings: UTF-8, UTF-16, US-ASCII, ISO-10646-UCS-2, ISO-8859-1, ISO-8859-2, ISO-88

  • Reader XI temp file location

    We are having an issue with our Term server users. Since moving to a server 2012 windows 8 environment we are unable to use the comment function in reader XI, as you can see it is completely greyed out. Have tested the same pdf file off of the server