Returning filtered records based on login password

Hi,
I'm using MySql / PHP / DW
I have a 'login.php' page which has two fields USERNAME & PASSWORD, and a 'jobs.php' page which displays a list of Client's jobs.
I need Client A to log in and only see Client A's jobs and so on for my various clients...
I have two tables, USER and JOBS.
USER TABLE
client_id (primary key)
username
password
access_level
JOBS TABLE
job_id (primary key)
client_id
client
site
install_date
I need 'jobs.php' to display Client A's jobs based on the username and / or password he has entered.
Do I have to create a query in MySql or can I achieve this within DW in recordsets or something? I'm very confused!
Thanks

I had to do something very similar using .asp and MSaccess many years ago, back then I had to create a query in Access which merged the two tables together and then I created a recordset from it in Dreamweaver. Can I replicate this using MySql / Phpmyadmin and have the query show up in Dreamweaver so I can create a recordset from it?
Back to present day...How do I retrieve the id of a record?
On the client records page I have entered this data below - can you tell me if this is correct? When I test it records are displayed but when I preview in browser the records page comes back empty.
Simple view:
Advanced view:

Similar Messages

  • Returning latest records based on specific conditions

    Hi Everyone, Thanks for everyone response for my queries. All responses are highly appreciated. I need one help in developing Sql query. I am
    using Oracle 11.2.
    I have table Test as below having columns as, ID;Name;Position;Level;Date_Added;Flag_Name;
    Suppose I have below data in table:
    ID       Name      Position      Level              Date_Added                Flag_Name
    1       Jack       Manager        10         10/29/2013 11:00:00 PM          Match
    2       Tom        Supervisor     20            10/31/2013 9:00:00 AM       NoMatch
    1       Jack       Manager        15          11/1/2013  10:00:00 AM          Error
    1       Jack       Manager        20         10/1/2013  9:00:00 AM           NoMatch
    3       John       Salesman      5           10/4/2013  2:00:00 PM           Error
    1       Jack       Manager        17         9/28/2013  2:00:00 AM           NoMatch
    2       Tom        Supervisor     12         11/2/2013  10:00:00 AM          NoMatch
    4       Remy       Accountant     12        11/4/2013  1:00:00 PM           Error
    4       Remy       Accountant     19         11/3/2013  2:00:00 AM           Error
    2       Tom        Supervisor     10            10/29/2013 7:00:00 PM           Error
    I need to return latest data in query based on combination of (ID;Name;Position) and date range with below conditions:
    1) Need to return latest records for Flag_Name other than Match.
    2) If latest record for combination of (ID;Name;Position) will come with Flag_Name as Error in that specified date range, then we need to look for this combination has Flag_Name as NoMatch anywhere before in table.
    3) If Flag_Name as NoMatch is found for this, then we need to return it. In this case also, if we found multiple records with Flag_Name as NoMatch for combination of (ID;Name;Position), then we need to return latest one.
    4) Else we find no record for combination of (ID;Name;Position) with Flag_Name as NoMatch in table, then we can return the latest record with Flag_Name as Error.
    While select ID;Name;Position should be unique combination, as we always return latest data for it.
    As per above table, if I need to return data for date range between 29-Oct-2013 and 5-Nov-2013, expected result will be like below:
    ID       Name      Position      Level         Date_Added                      Flag_Name    
    1       Jack       Manager        20              10/1/2013  9:00:00 AM           NoMatch
    2       Tom        Supervisor     12             11/2/2013  10:00:00 AM          NoMatch
    3       John       Salesman        5              10/4/2013  2:00:00 PM           Error
    4       Remy       Accountant     12           11/4/2013  1:00:00 PM           Error
    Please let me know if anyone has any doubt about the logic. Is it possible if we can do it in select statement rather than pl/sql code?
    All comments/suggestions will be highly appreciated.
    Thanks in advance.
    Regards
    Dev    

    First i didn't read topic exactly )))
    here is second way. I get with stmt from Karthick (thanks)
    with t
        as
        select 1 id, 'Jack' name, 'Manager'    position, 10 lvl, to_date('10/29/2013 11:00:00 PM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Match'   flag_name
          from dual union all
        select 2 id, 'Tom'  name, 'Supervisor' position, 20 lvl, to_date('10/31/2013 09:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'NoMatch' flag_name
          from dual union all
        select 1 id, 'Jack' name, 'Manager'    position, 15 lvl, to_date('11/1/2013  10:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Error'   flag_name
          from dual union all
      select 1 id, 'Jack' name, 'Manager'    position, 20 lvl, to_date('10/1/2013  09:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'NoMatch' flag_name
        from dual union all
      select 3 id, 'John' name, 'Salesman'   position,  5 lvl, to_date('10/4/2013  02:00:00 PM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Error'   flag_name
        from dual union all
      select 1 id, 'Jack' name, 'Manager'    position, 17 lvl, to_date('9/28/2013  02:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'NoMatch' flag_name
        from dual union all
      select 2 id, 'Tom'  name, 'Supervisor' position, 12 lvl, to_date('11/2/2013  10:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'NoMatch' flag_name
        from dual union all
      select 4 id, 'Remy' name, 'Accountant' position, 12 lvl, to_date('11/4/2013  01:00:00 PM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Error'   flag_name
        from dual union all
      select 4 id, 'Remy' name, 'Accountant' position, 19 lvl, to_date('11/3/2013  02:00:00 AM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Error'   flag_name
        from dual union all
      select 2 id, 'Tom'  name, 'Supervisor' position, 10 lvl, to_date('10/29/2013 07:00:00 PM', 'mm/dd/yyyy hh:mi:ss am') date_added, 'Error'   flag_name
        from dual
    select ID,
           Name,
           Position,
           max(lvl) keep (dense_rank first order by с desc, Date_Added desc) lvl,
           max(Date_Added) keep (dense_rank first order by с desc, Date_Added desc) Date_Added,
           min(Flag_Name) keep (dense_rank first order by с desc, Date_Added desc) Flag_Name
    from(
    select  ID,
                Name,
                Position,
                lvl,
                Date_Added,
                Flag_Name,           
                decode(flag_name, 'Error', -1, 1) с
    from T
    where flag_name != 'Match'
    group by ID,Name,Position
    ID
    NAME
    POSITION
    LVL
    DATE_ADDED
    FLAG_NAME
    1
    Jack
    Manager
    20
    01.10.2013 09:00:00
    NoMatch
    2
    Tom
    Supervisor
    12
    02.11.2013 10:00:00
    NoMatch
    3
    John
    Salesman
    5
    04.10.2013 14:00:00
    Error
    4
    Remy
    Accountant
    12
    04.11.2013 13:00:00
    Error
    Ramin Hashimzade
    Message was edited by: RaminHashimzadeh

  • User selection to return filtered record set

    Hi,
    I want to create a JSP which allows a user to enter search criteria for several columns of a table. I will use the entered values to set the sql where clause and produce the filtered record set. (eg the user enters a particular customer code and status code in order to see a list of orders placed by that customer which have the selected status code.)
    The problem I have is this: I want the input fields for the selection criteria to be combo boxes populated with values from the database.
    What is the best way to do this?

    Hi,
    I want to create a JSP which allows a user to enter search criteria for several columns of a table. I will use the entered values to set the sql where clause and produce the filtered record set. (eg the user enters a particular customer code and status code in order to see a list of orders placed by that customer which have the selected status code.)
    The problem I have is this: I want the input fields for the selection criteria to be combo boxes populated with values from the database.
    What is the best way to do this?

  • Query range must return one record based on the amount passed.

    Hi,
    Need to return the correct line_number based on the amout that falls within that range.
    Example;- if current amount value is 100 then line_number should return 1.
    if current amount value is 420 then line_number should return 4.
    Line_Num Amount
    *1 149.99*
    2 300
    3 400
    *4 500*
    5 9999999.99
    I need this in a query to resolve this, not PL/SQL.
    Thanks in advance.

    select min(line_num) from yourtable where amount >= &input_amount

  • TS3554 Tried setting login password on recently returned iMac after Seagate hard drive replaced. No space to type in a password or confirm it appeared so I chickened out and clicked on red dot to shut down window. I did, however, put my name as admin. now

    Tried setting login password onto iMac after it returned from Seagate exchange hard drive. Upgraded from leopard, snow leopard and currently upgraded to Lion, so as to have iCloud.Typed my name in as administrator and waited for a space to appear to type in password and confirm it. No space appeared so I shut that window down. Put iMac to sleep and when I returned and tried to access computer, it asks for a password which I did not put in! Now I'm stuffed. Cannot get into computer at all. Help appreciated. I'm not a techno wizard.

    Welcome to the Apple Support Communities
    Reset the password > https://discussions.apple.com/docs/DOC-4101

  • After typing login password at login screen osx lion attempts to login then returns to login screen

    after typing login password at login screen osx lion attempts to login then returns to login screen, any ideas?

    While we all have MacBooks in this forum most of us don’t run Lion. There's a Lion Support Community where everybody has Lion. You should also post this question there to increase your chances of getting an answer. https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion

  • Returning records based on the max timestamp

    I am writing a query to return records for each dat with max timestamp. so the query must return 1 record for each day with the latest timestamp. I am doing a partition over the timestamp column and wondering which analytic func gives the fastest result. This is in a data warehouse environment where there may be millions of recs.
    thanks

    My sample table has 3 columns - deptno, deptdesc, and eff_ts. There may be multiple rows for each day but I want to pick only the first (or last) record for each day.
    This is one query I am thinking about using analytic functions.
    SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
    select FIRST_VALUE(eff_ts)
    OVER (PARTITION BY trunc(eff_ts) ORDER BY eff_ts) eff_ts FROM test_dates)
    I can also use max (or min) timestamp and do a group by.
    SELECT deptno, deptdesc, eff_ts from test_dates where eff_ts in (
    select min(eff_ts) FROM test_dates group by trunc(eff_ts))
    Which is better (or is there any other better way) to use in a data warehousing env?

  • Parameter Field Value returns "no records"

    I am using Crystal 11 and am new to Crystal but not to other Reportwriters.  I have a Crystal report that has 2 parameter fields, one is "Enter Date" that prompts for the start and end date, the other "Select Items" prompts for the supply Item Numbers to be included in the report.  In the "Edit Parameter: Select Items:" edit/create parameter dialog, the Select Item parameter has "Allow Multiple values" and "Allow discrete values" set to true. The report runs fine and returns any items entered in the "Select Items" prompt that has usage during the start & end date.  My problem is ... if the entered Item Number for the Select Items parameter returns no records, I cannot report that Item Number as having zero usage.  I cannot find a way at the time of report running to identify and report the "not found" items.  I would also like to report the Start and End Dates parameters requested, but cannot, the Enter Date parameter returns an empty parameter field across the whole report.  I'm sure other users have had this problem of reporting the requested parameter values.   Need assistance.  

    Jeff's answer is one way to do it.  There are others:
    If you want the items with no data interspersed with the other items (say, in item number order), then you'd change the report to use your item master table and do a left join from that to the usage data.  If a field from the usage table is null, then there was no usage, and you can condition a message based on that.
    Or, if your parameter selects item numbers without some type of "ALL" option, then you can use arrays to keep track of which if the selected items printed.  Then in the report footer, compare the list of items reported to the parameter items, and show which item numbers had no usage.  (This might run a tad faster than the separate subreport that Jeff suggested - but maybe not...)
    HTH,
    Carl

  • Global Temp Table, always return  zero records

    I call the procedure which uses glbal temp Table, after executing the Proc which populates the Global temp table, i then run select query retrieve the result, but it alway return zero record. I am using transaction in order to avoid deletion of records in global temp table.
    whereas if i do the same thing in SQL navigator, it works
    Cn.ConnectionString = Constr
    Cn.Open()
    If FGC Is Nothing Then
    Multiple = True
    'Search by desc
    'packaging.pkg_msds.processavfg(null, ActiveInActive, BrandCode, Desc, Itemtype)
    SQL = "BEGIN packaging.pkg_msds.processavfg(null,'" & _
    ActiveInActive & "','" & _
    BrandCode & "','" & _
    Desc & "','" & _
    Itemtype & "'); end;"
    'Here it will return multiple FGC
    'need to combine them
    Else
    'search by FGC
    SQL = "BEGIN packaging.pkg_msds.processavfg('" & FGC & "','" & _
    ActiveInActive & "','" & _
    BrandCode & "',null,null); end;"
    'will alway return one FGC
    End If
    ' SQL = " DECLARE BEGIN rguo.pkg_msds.processAvedaFG('" & FGC & "'); end;"
    Stepp = 1
    Cmd.Connection = Cn
    Cmd.CommandType = Data.CommandType.Text
    Cmd.CommandText = SQL
    Dim Trans As System.Data.OracleClient.OracleTransaction
    Trans = Cn.BeginTransaction()
    Cmd.Transaction = Trans
    Dim Cnt As Integer
    Cnt = Cmd.ExecuteNonQuery
    'SQL = "SELECT rguo.pkg_msds.getPDSFGMass FROM dual"
    SQL = "select * from packaging.aveda_mass_XML"
    Cmd.CommandType = Data.CommandType.Text
    Cmd.CommandText = SQL
    Adp.SelectCommand = Cmd
    Stepp = 2
    Adp.Fill(Ds)
    If Ds.Tables(0).Rows.Count = 0 Then
    blError = True
    BlComposeXml = True
    Throw New Exception("No Record found for FGC(Finished Good Code=)" & FGC)
    End If
    'First Row, First Column contains Data as XML
    Stepp = 0
    Trans.Commit()

    Hi,
    This forum is for Oracle's Data Provider and you're using Microsoft's, but I was curious so I went ahead and tried it. It works fine for me. Here's the complete code I used, could you point out what are you doing differently?
    Cheers,
    Greg
    create global temporary table abc_tab(col1 varchar2(10));
    create or replace procedure ins_abc_tab(v1 varchar2) as
    begin
    insert into abc_tab values(v1);
    end;
    using System;
    using System.Data;
    using System.Data.OracleClient;
    class Program
        static void Main(string[] args)
            OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger");
            con.Open();
            OracleTransaction txn = con.BeginTransaction();
            OracleCommand cmd = new OracleCommand("begin ins_abc_tab('foo');end;", con);
            cmd.Transaction = txn;
            cmd.ExecuteNonQuery();
            cmd.CommandText = "select * from abc_tab";
            OracleDataAdapter da = new OracleDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            Console.WriteLine("rows found: {0}", ds.Tables[0].Rows.Count);
            // commit, cleanup, etc ommitted for clarity
    }

  • How do I reset my forgotten Mac Book Pro login password ?

    The "help" on my MacBook Pro insists I can change my forgotten login password by using my apple Id and password, by simply hitting the arrow beside the login password box. It appears after a failed attempt to enter your password at Login, however the drop down menu does not appear. The whole box shakes and that is all. In other places such as security and privacy all attempts are blocked , because I am asked to enter my (forgotten) password.
    Please advise, kind apple lovers.
    x

    If the user account is associated with an Apple ID, and you know that account password, the Apple ID can be used to reset your user account password.
    Otherwise, boot into Recovery by holding down the key combination command-R at startup. Release the keys when you see a gray screen with a spinning dial.
    When the OS X Utilities screen appears, select Utilities ▹ Terminal from the menu bar.
    In the Terminal window, type this:
    resetpassword
    That's one word with no spaces. Then press return. A Reset Password window opens.
    Select your boot volume if not already selected.
    Select your username from the menu labeled Select the user account if not already selected.
    Follow the prompts to reset the password. It's safest to choose a password that includes only the characters a-z, A-Z, and 0-9.
    Select  ▹ Restart from the menu bar.
    You should now be able to log in with the new password, but you won't be able to unlock the Keychain. If you've forgotten the Keychain password (which is ordinarily the same as your login password), there's no way to recover it. You’ll need to reset your keychain in the preferences of the Keychain Access application.

  • When trying to reset my login / password, text in red says not connected to internet please verify connection, when the macbook air IS connected to wifi.

    cannot reset forgotten login password.

    You don't need to be connected to the Internet to reset the password.
    Note: If you've activated FileVault, this procedure doesn't apply. Follow instead these instructions.
    Start up in Recovery mode. When the OS X Utilities window appears, select
              Utilities ▹ Terminal
    from the menu bar at the top of the screen—not from any of the items in the OS X Utilities window.
    In the window that opens, type this:
    resetp
    Press the tab key. The partial command you typed will automatically be completed to this:
    resetpassword
    Press return. A Reset Password window opens. Close the Terminal window to get it out of the way.
    Select the startup volume ("Macintosh HD," unless you gave it a different name) if not already selected. You won't be able to do this if FileVault is active.
    Select your username from the menu labeled Select the user account if not already selected.
    Follow the prompts to reset the password. It's safest to choose a password that includes only the characters a-z, A-Z, and 0-9.
    Select
               ▹ Restart
    from the menu bar.
    You should now be able to log in with the new password, but the Keychain will be reset (empty.) If you've forgotten the Keychain password (which is ordinarily the same as the login password), there's no way to recover it.

  • Can't create a folder without being asked for a login password.

    I'm running 10.9.5 on an iMac. When I try to create a folder I'm asked for my login password. When I try to move a file into the folder I'm asked again for my login password. This is very annoying. My other Mac running 10.4.8 doesn't do this.

    You may need to rebuild permissions on your user account. To do this,boot to your Recovery partition (holding down the Command and R keys while booting) and open Terminal from the Utilities menu. In Terminal, type:  ‘resetpassword’ (without the ’s), hit return, and select the admin user. You are not going to reset your password. Click on the icon for your Macs hard drive at the top. From the drop down below it select the user account which is having issues. At the bottom of the window, you'll see an area labeled Restore Home Directory Permissions and ACLs. Click the reset button there. The process takes a few minutes. When complete, restart.   
    Repair User Permissions

  • GroupFilter and sum(); filtered records should not be included in the sum()

    Hi All,
    I am working on a report that has the following requirement.
    1. Query records from the database (multiple queries)
    2. Filter records based on a certain criteria.
    3. Sum() the rows.
    4. Cannot use where clause because of the complexity of the report.
    I have achieved the above requirement using data-template with one exception where my sum() is including all the filtered rows in the summation. I DO NOT want the filtered rows to be included in the sum(). I know I could do sum() in layout-template using xslt.
    Is there a way to do this in data-template?
    My data-template looks something like
    <group name="g_dept" source="q_dept">
        <element name="dname" value="dname"/>
        <element name="d_salary" value="g_emp.salary" function="sum()"/>
        <group name="g_emp" source="q_emp" groupFilter="filterEmployees(:empno)">
           <element name="ename" value="ename"/>
           <element name="empno" value="empno"/>
           <element name="salary" value="salary"/>
        </group>
    </group>
    My data looks like
    10    Scott1    7865    $100
    10    Scott2    6875    $200
    10    Scott3    5678    $300
    10    Scott4    8657    $500 <-- filtered with pl/sql package
    My output should look like
    Dept: 10
    Scott1    7865    $100
    Scott2    6875    $200
    Scott3    5678    $300
    Total for 10: $600
    instead my output looks like
    Total for 10: $1100 <-- including filtered row Steve.
    Is this a feature or a bug in the data-template? not sure the order of events querying, filtering & summation. If anyone could answer, I really appreciate it.
    Thanks

    Was there ever an answer the original question with the groupfilter and sum()?
    I have a GL Report (bi pub 5.6.3 with ebusiness suite 11.5.10.2) that uses the oracle.apps.fnd.flex.kff.select (with security as the output type). In my lowest group (lines) i have a group filter that eliminates the row if the security is Y (to eliminate it from the XML and report). However, the sums that I'm doing are including all rows, not just the ones included in the data file.
    I too have the same issue as Kalagara, where I can't use the where clause to exclude the rows.
    Thanks - Jennifer

  • Parameter in select to returns all records.

    Post Author: ComputerMike
    CA Forum: Crystal Reports
    Hi,
    I have a "project" parameter I use in my select formula to return records based the project field.  I would like to pass a value like "All" or "*" and have all reords returned, to see the records for all the projects.  If I pass in "3" I would just get records for project 3.  "All" would give me all the projects.
    Thanks,
    Mike

    Post Author: GraemeG
    CA Forum: Crystal Reports
    Modify your selection formula to something like:
    (if {?project} <> "ALL" then   {table.project} = {?project}else   1 = 1)
    You have to specify an 'else' and the above is a cheat that makes sure everything is selected if 'ALL'  is entered. A suggestion - make 'ALL' your parameter default.

  • Selecting records based on month and year parameters

    Hi. I have a sql 2008 r2 stored procedure which needs modifying to return the data based on a start / end month and year.
    It's a large SP so I'll summarise - It accepts four parameters:
    @StartMonth NVARCHAR(10)
    @StartYear NVARCHAR(4)
    @EndMonth NVARCHAR(10)
    @EndYear NVARCHAR(4)
    The current WHERE clause is:
    WHERE ta.TimeByDay BETWEEN '01' + '-' + ltrim(LEFT(@StartMonth, 3)) + '-' + @StartYear
    AND convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay))) + '-' + ltrim(LEFT(@EndMonth, 3)) + '-' + @EndYear
    Example of input parameters:
    @StartMonth = N'January',
    @StartYear = N'2014',
    @EndMonth = N'February',
    @EndYear = N'2014',
    Result:
    The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
    (1 row(s) affected)
    However it executes correctly if we do either of the following:
    1) Run the SQL direct in QA and type in January and February rather than passing in the Start/End Month parameters
    2) As you can see we use the following datediff call to get the number of days per month. IF I replace this with '28', or '31' for example the query also runs (oddly number 1 above then also runs by executing the SP):
    convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay)))
    How do I update the WHERE clause to return records between a start/end month and year?
    I'm a day on this so any help appreciated.
    Thanks

    create function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
    returns datetime
    as
    begin
    declare @the_date datetime, @c_date datetime, @cth smallint
    set @cth = 0
    set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
    while month(@c_date) = @month
    begin
    if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
    if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
    set @c_date = dateadd(day,1,@c_date)
    end
    return @the_date
    end
    go
    create function Dates(@date datetime)
    returns @table table
    now datetime,
    today datetime,
    Month_start datetime,
    Month_end datetime,
    Prev_Month_Start datetime,
    Prev_Month_End datetime,
    Week_Start datetime,
    Week_End datetime,
    Prev_Week_Start datetime,
    Prev_Week_End datetime,
    Quarter_Start datetime,
    Quarter_End datetime,
    Prev_Quarter_Start datetime,
    Prev_Quarter_End datetime,
    Year_Start datetime,
    Year_End datetime,
    Prev_Year_Start datetime,
    Prev_Year_End datetime,
    Month_End_TS datetime,
    Prev_Month_End_TS datetime,
    Week_End_TS datetime,
    Prev_Week_End_TS datetime,
    Quarter_End_TS datetime,
    Prev_Quarter_End_TS datetime,
    Year_End_TS datetime,
    Prev_Year_End_TS datetime,
    Year smallint,
    Month smallint,
    Day smallint,
    Month_Name varchar(15),
    Day_Name varchar(15),
    WD smallint
    as
    begin
    if @date IS NULL set @date = getdate()
    insert into @table
    select
    @date as now,
    convert(datetime,convert(varchar,@date,101)) as today,
    dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
    dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
    dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
    dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
    dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
    dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
    dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
    dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
    convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
    convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
    dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
    dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
    dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
    dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
    dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
    dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
    dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
    dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
    dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
    dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
    Year(@date) as Year,
    Month(@date) as Month,
    Day(@Date) as Day,
    datename(month,@Date) as Month_Name,
    datename(WEEKDAY,@date) as Day_Name,
    datepart(weekday,@date) as WD
    return
    end
    go
    create function Holidays(@year smallint)
    returns @table table
    date datetime,
    type varchar(10),
    name varchar(25)
    as
    begin
    insert into @table
    select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
    select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
    select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
    select convert(varchar,@year)+'-01-07' ,'Holiday','Canada Day' UNION ALL
    select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
    select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
    select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
    select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
    select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
    select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day'
    update @table
    set date =
    case when name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
    when name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
    else date
    end
    return
    end
    go
    Using these functions (in place of a calendar table) you could do something like this:
    DECLARE @forumTable TABLE (sales MONEY, saleDate DATE)
    INSERT INTO @forumTable (sales, saleDate)
    VALUES
    (123.45, '2014-01-05'),(678.90, '2014-01-06'),(111.21, '2014-01-07'),(314.15, '2014-01-08'),(161.71, '2014-01-09'),
    (819.20, '2014-02-05'),(212.22, '2014-02-06'),(324.25, '2014-02-07'),(262.72, '2014-02-08'),(829.30, '2014-02-09')
    SELECT SUM(f.sales), d.month_end
    FROM @forumTable f
    CROSS APPLY sandbox.dbo.dates(f.saleDate) d
    GROUP BY d.month_end

Maybe you are looking for

  • Why can I not get v30 to have the same layout as v26?

    In v26.0 of Firefox, I configured my menu bar ("File", "Edit", etc) to contain the following after the menu items: - back button - forward button - reload/stop button - home button - progress indicator - site rating indicator - address bar - tab-list

  • 80GB Vid Disconnect Issue

    My 80GB iPod is only 2 weeks old. I have been using manual download for all songs and pictures since I have two computers. My library is on my home PC, but I connect at work to play through my computer and to purchase from iTunes (I transfer purchase

  • Multilingual based on client IP

    Hi all, i'm newbie in adf and i'm facing problem:-- i'm making multilingual functionality on page,which is based on ip of client m/c ...based on tht it tells locale and on basis of locale .....corresponding property file will call. so on jsp page dro

  • PLZ HELP ME DONNO WHAT TO DO

    Please help me. Last summer holiday i was in ireland and i bought an ipod 20gb color display with click wheel. It was near a year ago.Everything was good until 2 months ago.First hedphones stared snaring and clicking when music was on - but thats not

  • Cache Refresh Error and Adaptors Missing in RWB Monitoring

    Hi, We are in NW04s (SP13) of PI. 3 problems: 1. SXI_CACHE Partial Cache Refresh gives OK (Green) Full Cache Refresh gives error: "Error During last attempt to refresh cache" Double click on the red message indicates: Error Id: UPDATE HTTP status cod