A new topic of code formatting

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    Copying text from a post

    Dear Experts,

    i need help in calculating time difference between two dates portion by Date, the difference will be calculated with the first day last Attendance = 1 with very next Attendance =1 of next day. and same will repeat second day last Attendance = 1 with very next Attendance =1 of next day.

    Sample data SQL:

    Drop Table #tmp_employees
    CREATE TABLE #tmp_employees
    (
    Name VARCHAR(30) NULL,
    EmployeNo VARCHAR(30) NULL,
    Date DATETIME NULL,
    Value INT NULL,
    Attendence INT NULL
    --,[Calculate Hr's difference] INT NULL
    )
    GO
    insert into #tmp_employees
    Values
    ('John','123','3/29/19 9:00 AM','10','0'),
    ('Raju','234','3/29/19 10:00 AM','20','0'),
    ('Chris','345','3/29/19 10:00 AM','50','1'),
    ('Ram','654','3/29/19 9:00 AM','10','1'),
    ('Robart','345','3/29/19 12:00 PM','10','0'),
    ('John','123','3/30/19 9:00 AM','10','0'),
    ('Raju','234','3/30/19 9:10 AM','20','1'),
    ('Chris','345','3/30/19 9:00 AM','50','1'),
    ('Ram','654','3/30/19 9:00 AM','10','1'),
    ('Robart','345','3/30/19 9:00 AM','10','0'),
    ('John','123','3/31/19 9:00 AM','10','0'),
    ('Raju','234','3/31/19 9:20 AM','20','1'),
    ('Chris','345','3/31/19 9:00 AM','50','0'),
    ('Ram','654','3/31/19 9:00 AM','10','0')

    I need some answer

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    Steve Jones - SSC Editor wrote:

    Copying text from a post Dear Experts, i need help in calculating time difference between two dates portion by Date, the difference will be calculated with the first day last Attendance = 1 with very next Attendance =1 of next day. and same will repeat second day last Attendance = 1 with very next Attendance =1 of next day. Sample data SQL:

    Drop Table #tmp_employees
    CREATE TABLE #tmp_employees
    (
    Name VARCHAR(30) NULL,
    EmployeNo VARCHAR(30) NULL,
    Date DATETIME NULL,
    Value INT NULL,
    Attendence INT NULL
    --,[Calculate Hr's difference] INT NULL
    )
    GO
    insert into #tmp_employees
    Values
    ('John','123','3/29/19 9:00 AM','10','0'),
    ('Raju','234','3/29/19 10:00 AM','20','0'),
    ('Chris','345','3/29/19 10:00 AM','50','1'),
    ('Ram','654','3/29/19 9:00 AM','10','1'),
    ('Robart','345','3/29/19 12:00 PM','10','0'),
    ('John','123','3/30/19 9:00 AM','10','0'),
    ('Raju','234','3/30/19 9:10 AM','20','1'),
    ('Chris','345','3/30/19 9:00 AM','50','1'),
    ('Ram','654','3/30/19 9:00 AM','10','1'),
    ('Robart','345','3/30/19 9:00 AM','10','0'),
    ('John','123','3/31/19 9:00 AM','10','0'),
    ('Raju','234','3/31/19 9:20 AM','20','1'),
    ('Chris','345','3/31/19 9:00 AM','50','0'),
    ('Ram','654','3/31/19 9:00 AM','10','0')

    I need some answer

    I'm quoting a reply here. Have you thought about actually trying some differnet code. Maybe you want to try this code, or something similar:

    EXECUTE AS USER = 'SallyDev'
    GO
    EXEC sp_columns @table_name = 'Articles'
    GO
    REVERT
  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    Trying some bbcode here.

    This is bold if it works.

    This is italics

    This is bbcode italics

    This is code below

    Select *

    from pleasework

  • anonuser

    SSC Enthusiast

    Points: 130

    bold test

     

  • anonuser

    SSC Enthusiast

    Points: 130

    Normal user trying to format code

    DECLARE

    @MyDate DATE = '2015-08-27'

    , @MyTime TIME = '15:33:21.057';

    SELECT MyDateTime1 = CAST(@MyDate AS DATETIME) + CAST(@MyTime AS DATETIME);

  • Sue_H

    SSC Guru

    Points: 90009

    Abnormal user trying some of this too

    <b> manual bold </b> to see if that works.

    Toolbar bold

    asdf

  • Sue_H

    SSC Guru

    Points: 90009

    My bad...duh...

    manual bold using the brackets

  • Sue_H

    SSC Guru

    Points: 90009

    Sue_H wrote:

    My bad...duh... manual bold using the brackets

     

    So manual works as well.

    URLs -

    This goes to storage engine blog and of course MS has no broken links

  • Sue_H

    SSC Guru

    Points: 90009

    Earlier today, I had to clear my cookies for SSC to get the toolbar and for all of this to work. That may be why others are still complaining. The only time it didn't work since was a user error.

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    Thanks, Sue. I'll make a note about clearing cookies in a few posts.

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    This is some PoSh

    $loops = 10000
    $i = 1
    $server = "Plato\SQL2017"
    $db = "OneThousand"
    $start = Get-Date
    while ($i -lt $loops) {
    $number = Get-Random -Maximum 1000 -Minimum 1
    $query = "insert mytable" + $number + " select " + $number + ", replicate(CHAR(65), 1000)"
    Invoke-Sqlcmd -ServerInstance $server -Database $db -Query $query
    #write-host($number)
    $i = $i + 1
    }
    $end = Get-Date
    $Interval = New-TimeSpan -End $end -Start $start
    write-host($start)
    Write-Host($end)
    write-host($Interval)

    Hope it looks good

  • anonuser

    SSC Enthusiast

    Points: 130

    Steve Jones - SSC Editor wrote:

    Copying text from a post Dear Experts, i need help in calculating time difference between two dates portion by Date, the difference will be calculated with the first day last Attendance = 1 with very next Attendance =1 of next day. and same will repeat second day last Attendance = 1 with very next Attendance =1 of next day. Sample data SQL:

    Drop Table #tmp_employees
    CREATE TABLE #tmp_employees
    (
    Name VARCHAR(30) NULL,
    EmployeNo VARCHAR(30) NULL,
    Date DATETIME NULL,
    Value INT NULL,
    Attendence INT NULL
    --,[Calculate Hr's difference] INT NULL
    )
    GO
    insert into #tmp_employees
    Values
    ('John','123','3/29/19 9:00 AM','10','0'),
    ('Raju','234','3/29/19 10:00 AM','20','0'),
    ('Chris','345','3/29/19 10:00 AM','50','1'),
    ('Ram','654','3/29/19 9:00 AM','10','1'),
    ('Robart','345','3/29/19 12:00 PM','10','0'),
    ('John','123','3/30/19 9:00 AM','10','0'),
    ('Raju','234','3/30/19 9:10 AM','20','1'),
    ('Chris','345','3/30/19 9:00 AM','50','1'),
    ('Ram','654','3/30/19 9:00 AM','10','1'),
    ('Robart','345','3/30/19 9:00 AM','10','0'),
    ('John','123','3/31/19 9:00 AM','10','0'),
    ('Raju','234','3/31/19 9:20 AM','20','1'),
    ('Chris','345','3/31/19 9:00 AM','50','0'),
    ('Ram','654','3/31/19 9:00 AM','10','0')

    I need some answer

     

    Testing quotes

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    anonuser wrote:

    Steve Jones - SSC Editor wrote:

    Copying text from a post Dear Experts, i need help in calculating time difference between two dates portion by Date, the difference will be calculated with the first day last Attendance = 1 with very next Attendance =1 of next day. and same will repeat second day last Attendance = 1 with very next Attendance =1 of next day. Sample data SQL:

    Drop Table #tmp_employees
    CREATE TABLE #tmp_employees
    (
    Name VARCHAR(30) NULL,
    EmployeNo VARCHAR(30) NULL,
    Date DATETIME NULL,
    Value INT NULL,
    Attendence INT NULL
    --,[Calculate Hr's difference] INT NULL
    )
    GO
    insert into #tmp_employees
    Values
    ('John','123','3/29/19 9:00 AM','10','0'),
    ('Raju','234','3/29/19 10:00 AM','20','0'),
    ('Chris','345','3/29/19 10:00 AM','50','1'),
    ('Ram','654','3/29/19 9:00 AM','10','1'),
    ('Robart','345','3/29/19 12:00 PM','10','0'),
    ('John','123','3/30/19 9:00 AM','10','0'),
    ('Raju','234','3/30/19 9:10 AM','20','1'),
    ('Chris','345','3/30/19 9:00 AM','50','1'),
    ('Ram','654','3/30/19 9:00 AM','10','1'),
    ('Robart','345','3/30/19 9:00 AM','10','0'),
    ('John','123','3/31/19 9:00 AM','10','0'),
    ('Raju','234','3/31/19 9:20 AM','20','1'),
    ('Chris','345','3/31/19 9:00 AM','50','0'),
    ('Ram','654','3/31/19 9:00 AM','10','0')

    I need some answer

      Testing quotes

     

    Is this quoted?

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 715101

    A bit more code to check

    SELECT a.PharmNo, a.ClaimNo, a.ClaimDate, b.PharmNo, b.ClaimNo, b.ClaimDate
    FROM Claim AS a
    INNER JOIN Claim AS b ON a.PharmNo = b.PharmNo AND a.ClaimDate < b.ClaimDate WHERE wehaveosmething = somevalue and someothervlaue <> areallybadvalue or user_id = 'Steve' and logicalconstructs = 'this doesn't make sense';
  • Sue_H

    SSC Guru

    Points: 90009

    Spacing...

    SELECT 
    sp.state_desc,
    sp.permission_name,
    p.name,
    sp.class_desc
    FROM sys.server_permissions AS sp
    JOIN sys.server_principals AS p
    ON sp.grantee_principal_id = p.principal_id
    WHERE permission_name = 'VIEW SERVER STATE'


    --after some inserted lines...
    SELECT
    p.[name],
    sp.permission_name,
    sp.state_desc,
    sp.class_desc
    FROM sys.server_permissions AS sp
    JOIN sys.server_principals AS p
    ON sp.grantee_principal_id = p.principal_id
    WHERE p.[name] = 'YourTestLogin'

    --and some more breaks pasted from SSMS
    --comment



    EXEC sp_dbfixedrolepermission

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic. Login to reply