logo
down
shadow

Select * from x where column is quarter


Select * from x where column is quarter

By : Wilson G
Date : November 22 2020, 03:01 PM
I hope this helps . A way is to use MONTH() and DAY()
code :
Select * 
from Table1.dbo.TableOne
where month(Period) = 3 and day(Period) = 31
;
Select * 
from Table1.dbo.TableOne
where datepart(month,Period) = 3 and datepart(day,Period) = 31
;
Select * 
from Table1.dbo.TableOne
where right(convert(varchar(8),Period,112),4) = '0331'
;
Select * 
from Table1.dbo.TableOne
where format(Period,'MMdd') = '0331'
;


Share : facebook icon twitter icon
How to find the previous quarter value based on current quarter in PostgreSQL?

How to find the previous quarter value based on current quarter in PostgreSQL?


By : DoubleDP
Date : March 29 2020, 07:55 AM
this one helps. You need to "trunc" the date to the beginning of its quarter, the subtract a day, and then get the quarter for that date:
code :
extract(quarter from date_trunc('quarter', date '2015-01-01')::date - 1)
to_char(date_trunc('quarter', date '2015-01-01')::date - 1, 'yyyy-q');
How to automatically select the last rolling quarter from a table with "Quarter" and "Year" being th

How to automatically select the last rolling quarter from a table with "Quarter" and "Year" being th


By : Hitesh Thakkar
Date : March 29 2020, 07:55 AM
Hope that helps Use the current year and current quarter to your advantage by utilizing DATEPART. This query below can be built out for as many years as you need
code :
DECLARE @tblDates TABLE
    (
    Dt Date,
    [Year] int,
    [Quarter] int
    )

--Identify the boundary condition
DECLARE @CurrentQuarter INT
SET @CurrentQuarter = (SELECT DATEPART(QQ, GETDATE()))

--Add in some test data
INSERT INTO @tblDates 
    SELECT GETDATE(), DATEPART(YY, GETDATE()), DATEPART(QQ, GETDATE())
    UNION SELECT DATEADD(QQ, -1, GETDATE()), DATEPART(YY, DATEADD(QQ, -1, GETDATE())), DATEPART(QQ, DATEADD(QQ, -1, GETDATE()))
    UNION SELECT DATEADD(QQ, -2, GETDATE()), DATEPART(YY, DATEADD(QQ, -2, GETDATE())), DATEPART(QQ, DATEADD(QQ, -2, GETDATE()))
    UNION SELECT DATEADD(QQ, -3, GETDATE()), DATEPART(YY, DATEADD(QQ, -3, GETDATE())), DATEPART(QQ, DATEADD(QQ, -3, GETDATE()))
    UNION SELECT DATEADD(QQ, -4, GETDATE()), DATEPART(YY, DATEADD(QQ, -4, GETDATE())), DATEPART(QQ, DATEADD(QQ, -4, GETDATE()))
    UNION SELECT DATEADD(QQ, -5, GETDATE()), DATEPART(YY, DATEADD(QQ, -5, GETDATE())), DATEPART(QQ, DATEADD(QQ, -5, GETDATE()))
    UNION SELECT DATEADD(QQ, -6, GETDATE()), DATEPART(YY, DATEADD(QQ, -6, GETDATE())), DATEPART(QQ, DATEADD(QQ, -6, GETDATE()))
    UNION SELECT DATEADD(QQ, -7, GETDATE()), DATEPART(YY, DATEADD(QQ, -7, GETDATE())), DATEPART(QQ, DATEADD(QQ, -7, GETDATE()))


SELECT * FROM @tblDates
    WHERE 
        (
        --This year, but prior to the current quarter
        [Year] = DATEPART(YY, GETDATE()) AND [Quarter] < @CurrentQuarter
        )
        OR
        (
        --Last year, but greater than or equal to current quarter will book-end the last 4 quarters
        [Year] = DATEPART(YY, GETDATE()) - 1 AND [Quarter] >=@CurrentQuarter
        )
create new column to store quarter of year from existing datetime column

create new column to store quarter of year from existing datetime column


By : Leo Palomares
Date : March 29 2020, 07:55 AM
This might help you You can directly use DATEPART() function with Quarter option to fetch Quarter to which date belongs
code :
SELECT *, 'Q' + CAST(DATEPART(QUARTER, DateOfDisc) AS VARCHAR(1)) as Quarter
FROM TableName
SQL- Current quarter data has to be truncated and reloaded but the previous quarter should remain untouched

SQL- Current quarter data has to be truncated and reloaded but the previous quarter should remain untouched


By : Jobayer Ahmed Mickey
Date : March 29 2020, 07:55 AM
around this issue if your @usedate has values like 20160331 then we need to extract the quarter from that and then delete the records from fact which has the same quarter .
code :
DELETE FROM [dbo].[Fact] 
WHERE  Datepart(Quarter,Quarterkey) = datepart(Quarter,@useDate);

INSERT INTO [dbo].[Fact]
SELECT * from stg
Where Datepart(Quarter,Quarterkey) not in (select 
datepart(Quarter,@UseDate);
Create new column: divides current year quarter by last year quarter minus 1

Create new column: divides current year quarter by last year quarter minus 1


By : Abyshekk25
Date : March 29 2020, 07:55 AM
With these it helps We can create a grouping column by extracting the quarter part and then with mutate_at, divide the lag of the columns by the column values and subtract from 1.
code :
library(dplyr)
library(stringr)
df %>%
    group_by(grp = str_extract(x0, "Q\\d")) %>% 
    mutate_at(vars('x1', 'x2'), funs(div = round(1- lag(.)/., 2))) %>%
    ungroup %>%
    select(-grp)
Related Posts Related Posts :
  • Tail log backup message warning before restoring a backup
  • T-SQL query with aggregates returning a non empty result set when predicate is false
  • Difference between top 2 over multiple rows
  • SQL Server 2016 SSIS Conditionally Overwrite Text File
  • The column was specified multiple times
  • is there something faster than Enumerable.Except<TSource> Method?
  • I need to take database back up database name with date
  • Numeric to money conversion fails for bigger value when using (DT_CY) type cast in derived column component
  • SQL server stored procedure insert with dynamic exec
  • How to grant unsafe assembly to a username found dynamically?
  • How can I loop though columns by name in an SSIS Script component?
  • SSRS Export to Excel Filter To Many Tabs
  • SQL Server 2012 Management Studio hangs
  • Can NOLOCK cause DISTINCT to fail?
  • SSRS Mobile Reports Distinct Count
  • Append api data to Amazon AWS SQL Server database
  • Merge columns together from multiples tables, columns not in order
  • Why Can't I See SQL Server Compact After I Install It?
  • SQL Server - Where Like statement with variable returning no results
  • SQL query to find non-matching fields in certain rows
  • SQL Server - Select between 2 dates of type DD/MM/YYYY
  • SQL Geography Datatype , checking Point in Polygon , STIntersects producing wrong result
  • A positional parameter cannot be found that accepts argument
  • Array var in SQL Server 2008
  • Using a variable in a sqsh script is not working while querying in sql server
  • Error Executing Query String
  • SQL view with substring in WHERE clause?
  • Specify Xml index storage location in Sql Server
  • How to push Spark dataframe to Sql Server table when set_identity is off?
  • Create index error -The object name contains more than the maximum number of prefixes. The maximum is 2
  • T-SQL: Minimum number of characters to remove/replace so that one string is substring of another
  • sql query that gets the difference between 2 recent rows for every row item that occurs more than once in a table
  • SSIS conditionally import if source is available
  • How to set SQL user password when deploying database project using CI/CD pipeline
  • SQL: How can I Parse firstname, lastname and title from fullname?
  • Should I store XML declaration in database and return using WebApi
  • SSIS Foreach loop error on CSV files
  • Azure SQL as Publisher
  • SSRS 2016 Mobile Reports Error with missing dataset
  • SQL 2005: Optimize upsert-like Stored Procedure using Cursor, possible?
  • SQLSERVER - How to list Procs created by a particular user?
  • SSIS Expression to get last day of the month given YYYYMM
  • how to sum up all time values on a given date?
  • Text Clause Explanation
  • SQL Server 2016 - Can't to log into SSMS after install
  • SQL Server table with different case in PowerShell SMO vs SSMS
  • Transpose and Create Variables
  • SQL : Output multiple left joined rows as one record for csv file
  • Removing Date From Date/Time Column
  • Subquery a Cast Function
  • Set based stacking update query
  • Can someone explain the `BypassPrepare` connection-parameter used when building an ETL via SSIS and VS?
  • What is the optimal way to get only latest ID's from table in SQL
  • How to join JSON with table?
  • Transforming a sql table into its inverse
  • Azure SQL Database Pricing
  • Log Reader error while adding a node in SQL Server peer to peer replication
  • Correct way to convert Month Name and Year to complete date SQL Server
  • Select records that appear twice, with a slight difference
  • tsql display value on first row of each group
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org