Query to find First sunday of march and Second Sunday of November in SQL 2008
Hi,
I want query to find Second sunday of march and First Sunday of November in SQL 2008. This query can be used for Daylight savings(MST).
Thanks in Advance.
Regards,
LuckyAbdul
declare @d datetime,@d1 datetime
set @d = '20140301'
set @d1='20081101'
SELECT @d1
declare @baseMonday datetime
set @baseMonday = '17530101'
select
@baseMonday + datediff(day,@baseMonday,@d)/7*7+13 as Sunday,
@baseMonday + datediff(day,@baseMonday,@d1)/7*7+6 as Sunday1
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
To get date of second sunday in march and first sunday in november of year
Hi all,
i need some java code to get date of second sunday in march and first sunday in november of every year.
this is very urgent
plz help
thanks in advance
jhansiHi,
Check below links for UDF's.
UDF
http://flickr.com/photos/8764045@N06/
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e55f9548dd
Example 1
http://www.flickr.com/photo_zoom.gne?id=544183191&size=o
http://www.flickr.com/photo_zoom.gne?id=544183195&size=o
http://www.flickr.com/photo_zoom.gne?id=544183225&size=o
http://www.flickr.com/photo_zoom.gne?id=544183233&size=o
Example 2
http://www.flickr.com/photo_zoom.gne?id=545133789&size=o
http://www.flickr.com/photo_zoom.gne?id=545133791&size=o
http://www.flickr.com/photo_zoom.gne?id=545133801&size=o
http://www.flickr.com/photo_zoom.gne?id=545133807&size=o
http://www.flickr.com/photo_zoom.gne?id=545133811&size=o
http://www.flickr.com/photo_zoom.gne?id=545138911&size=o
http://www.flickr.com/photo_zoom.gne?id=545138913&size=o
http://www.flickr.com/photo_zoom.gne?id=545138915&size=o
http://www.flickr.com/photo_zoom.gne?id=545138917&size=o
http://www.flickr.com/photo_zoom.gne?id=545138947&size=o
http://www.flickr.com/photo_zoom.gne?id=545138951&size=o
http://www.flickr.com/photo_zoom.gne?id=545005958&size=o
Example 3
http://www.flickr.com/photo_zoom.gne?id=549186611&size=o
http://www.flickr.com/photo_zoom.gne?id=549186651&size=o
http://java.sun.com/j2se/1.5.0/docs/api/
/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi
/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports
http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d046c490-0201-0010-84b6-9df523cbca31
Regards,
Phani
Reward Points if Helpful -
Query to find first and last call made by selected number for date range
Hi,
query to find first and last call made by selected number for date range
according to filter:
mobile_no : 989.....
call_date_from : 25-april-2013
call_date_to : 26-april-2013
Please helpHi,
It sounds like you want a Top-N Query , something like this:
WITH got_nums AS
SELECT table_x.* -- or list columns wanted
, ROW_NUMBER () OVER (ORDER BY call_date ) AS a_num
, ROW_NUMBER () OVER (ORDER BY call_date DESC) AS d_num
FROM table_x
WHERE mobile_no = 989
AND call_date >= DATE '2013-04-25'
AND call_date < DATE '2013-04-26' + 1
SELECT * -- or list all columns except a_num and d_num
FROM got_nums
WHERE 1 IN (a_num, d_num)
;This forum is devoted to the SQL*Plus and iSQL*Plus front ends. This question doesn't have anything to do with any front end, does it? In the future, you'll get better response if you post questions like this in the PL/SQL.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the SQL forum FAQ {message:id=9360002} -
Query to find all the view name and their size in GB
Hi,
What is the query to find all the view name and their size in GB.I am aware of joining all_views and user_segments but this is not serving the purpose.is there any table i need to join to get the desired result
ThanksYou could of course be thinking of views as they are stored in other RDBMS' as some of them actually create the view as a table on the database with a copy of the data in it and maintain that data as the base tables are updated.
As already mentioned, Oracle just stores the SQL of the View and executes that SQL when the view is queried.
Alternatively, Oracle also has "materialized views" which are created as snapshots of the data and will have a size. This data is updated (refreshed) based on the parameters used when creating the materialized view which means that it will either be, commonly, when a commit is issued or when a refresh is explicitly requested (refresh on demand). -
First derived wage type and second derived wage type
Hi all,
Can any of u elaborate in detail what is the use of first derived wage type and second derived wage type in v_512w_b.
Regards,
PrasadHi,
This table allows you to make calculation for current wage type and generate 2 more.
This is hypothetical example: according to the law for overtime during weekend employee is entitled for hourly compensation for every hour worked, extra pay of 50% for overtime, and extra pay of 20% for work during weekend. All these payments should be reflected on payslip.
Then you set WT: 1001 - Hourly rate, 1002 - Overtime, 1003 - Work in WE.
After that you specify generation rule for WT 1003 that it must be generated for every overtime hour worked in WE.
In table V_512W_B you set valaution bases:
Current WT
Valuation basis - 01, statement WT - 1003, % rate - 20%
1st derived WT
Valuation basis - 01, statement WT - 1001, % rate - 100%
2nd derived WT
Valuation basis - 01, statement WT - 1002, % rate - 50%
For example, employee worked 5 hours overtime during WE, and hourly rate is 10 USD, then he will get in his payslip:
WT 1001 - 5 hours 50 USD
WT 1002 - 5 hours 25 USD
WT 1003 - 5 hours 10 USD.
Wage types 1001 and 1002 were derived from WT 1003.
Cheers -
Pages can't create kind of document first page on vertical and second page on horizon
help me i won't create kind of document are first page on vertical and second page on horizon.
pages on iOS dosnt support making new documents with landscape view. I think this would also make it so you could not combine the two orientations in a single document.
I was able to get a landscape document made by making it on the desktop, emailing it to myself, then saving it in pages on my ipad. Not sure if that would work for a combination document.
Jason -
Looking for a query to find first/last dates in overlapping dates...
Hi,
I'm looking for a query to find the first dates and last dates in a table conaining overlapping dates.
I have a subscription table which has for each Customer start and end date for different subscriptions.
I want to know the different ranges of date where there is subscriptions active.
so if the table has this:
CustID, Start date, end date
1, 2008-01-01, 2012-06-06
1 ,2009-01-01, 2011-01-01
1, 2011-01-01, 2013-02-02
1, 2013-01-01, 2013-08-08
1, 2014-01-01, 2014-04-04
I want to produce this result:
custid, range start, range end
1, 2008-01-01, 2013-08-08
1, 2014-01-01, 2014-04-04
the first row is the range identified from the 4 rows in my subscription table.
thanks :)I think I found it...
http://stackoverflow.com/questions/5213484/eliminate-and-reduce-overlapping-date-ranges
let me try this method
Hi,
m writing to follow up with you on this post. Thanks for you posting a reply to share your workground. Was the problem resolved after performing the above link? If you are satisfied with the above solution, I’d like to mark this issue as "Answered".
Please also feel free to unmark the issue, with any new findings or concerns you may have.
Thanks,
Sofiya Li
If you have any feedback on our support, please click here.
Sofiya Li
TechNet Community Support -
Query to find the list of workbooks and worksheets assiciated to those book
Hi Gurus,
Could you help me with the tables / Query to fetch the list of workbooks and associated worksheets names as welll.
Thanks in advance!!
Rgds,
SantoshHi Santosh
The whole point of the STATS table is to allow you to query performance, who did what and when. The database itself does not keep such statistics so if you disable Discoverer's method of capturing these you have no way of knowing who did what and when.
Without this it is impossible to say. I would strongly recommend you enable the capturing of statistics.
The reason you cannot directly query a WORKBOOK to determine what WORKSHEETS are associated with it is because that information is stored as binary information and not in SQL format.
Discoverer 10g has the capability of providing detailed information on the EUL. This feature is not offered "out of the box" but can be easily enabled.
The EUL Administrator can enable the feature by completing the following steps (see also MOS Note 556932.1):
1. Log on to SQL*Plus as the Discoverer Administrator on the machine where Discoverer Administration Edition is installed.
2. Execute the EUL5.SQL script found in the *$ORACLE_HOME\discoverer\util* directory. (This script will create the necessary database objects.)
NOTE: If you are using an Oracle Applications mode EUL, you must also run the eul5_apps.sql file in the $ORACLE_HOME\discoverer\util directory. This script must be run as the EUL owner, and not the Oracle Applications SYSADMIN user.
4. Exit SQL*Plus and log on to the Discoverer Administration Edition product (as the EUL Administrator).
5. From the menu bar, select File | Import.
6. Import the EUL5.EEX file from the ORACLE_HOME\discoverer directory. Once the EUL import is complete, a new business area will be created and visible called The Discoverer V5 EUL. This is the business area that provides the details on the EUL.
EUL Management Workbooks for Discoverer Administrators
The EUL5.EEX file also imports four pre-built Discoverer workbooks. These workbooks are automatically saved to the database during the EEX import and can be executed in Discoverer Plus, Viewer or Desktop:
EUL Workbook Management - shows which workbooks are shared with which users. Examine worksheets to find the folders, items, joins and conditions they depend upon.
EUL Access - This Workbook indicates if a current EUL exists in this users schema. It also displays the EUL's in other user schemas that this user can access.
EUL Query Statistics - Find out which workbooks and worksheets are being used by whom. Examine users ad-hoc queries.
Lineage - Hyper Drill from Discoverer to find a folder or Items Lineage in Oracle Warehouse Builder. To enable the Hyper drill, you will first need to run the Lineage.sql script.
The Discoverer Administrator can use the pre-built workbooks or build their own EUL management workbooks by using the Discoverer V5 EUL business area.
Best wishes
Michael -
Query to find out the table name and column name..
Hi Experts,
I have an Oracle DB in which has more than 50 tables and 100,000 records. I want to get the record which contains *"ITxtVarValue references a non existing text"* the text.
Is there any query there to find out the table name and column name of this particular record where it reside?
Please help. Any help will be rewarded.
Thanks,
GUsing this forum's search function, I found a thread that should give you an idea: How to find out a tablename
C. -
Need MDX query to find something like date diff and Date Range for last 10 days
Hi ,
I need two Query .First Query for below;
I have below data in table like.
Cat StartDate EndDate
A 2000-01-01 2000-01-15
B 2000-01-02 2000-01-30
C 2000-01-01 2000-01-31
D 2000-02-01 2000-02-28
A 2000-01-10 2000-01-31
I need if Startdate and Date completes whole one month then set status =1 else 0 using MDX query.
like this ;
Cat StartDate EndDate Status
A 2000-01-01 2000-01-15 1
B 2000-01-02 2000-01-30 0
C 2000-01-01 2000-01-31 1
D 2000-02-01 2000-02-28 1
A 2000-01-10 2000-01-31 1
In second query I need last 10 days from current days like;
Now = 8/20/2014
output will be ;
8/20/2014
8/19/2014
8/18/2014
8/17/2014
8/16/2014
8/15/2014
8/14/2014
8/13/2014
8/12/2014
8/11/2014
8/10/2014
Please help me .
ThanksHi Prajapati,
In your scenario, you can use Properties and Datediff function to achieve your requirement. Since not know the structure of your cube, we cannot give you the esact query.
I have tested it on the AdventureWorks cube, the query below is for you reference.
WITH MEMBER [Measures].[StartDate]
AS
[Employee].[Employee Department].CURRENTMEMBER.PROPERTIES('Start Date')
MEMBER [Measures].[WorkYear]
AS
DATEDIFF('yyyy',[Measures].[StartDate],NOW())
MEMBER [Measures].[Status]
AS
IIF(DATEDIFF('yyyy',[Measures].[StartDate],NOW())>10,1,0)
SELECT {[Measures].[StartDate],[Measures].[WorkYear],[Measures].[Status]} ON 0,
[Employee].[Employee Department].[Employee].MEMBERS ON 1
FROM [Adventure Works]
Results
Reference
http://msdn.microsoft.com/en-us/library/ms144821.aspx
Regards,
Charlie Liao
TechNet Community Support -
SQL Query to find SUM elimating MAX n and MIN n values
Dear Gurus,
I am currently looking for a query which will provide the sum of a column eliminating the MAX n and MIN n values.
For Example,
If I have 7 values, and if n = 2, then the sum would be (23+26+36), if n = 1 then sum (14+23+26+36+39) and n will be always lesser than total no of values / 2.
12
14
23
26
36
39
45
Note: working in oracle 10g versiontry this
with t as
(select 12 col from dual union all
select 14 col from dual union all
select 23 col from dual union all
select 26 col from dual union all
select 36 col from dual union all
select 39 col from dual union all
select 45 col from dual
select sum(col) from
select col,rn from
(select col, rownum rn from (select col from t order by col))
where rn > (select &n from dual) and rn <= (select count(*) from t) - &n
)also
with t as
(select 12 col from dual union all
select 14 col from dual union all
select 2 col from dual union all
select 26 col from dual union all
select 36 col from dual union all
select 3 col from dual union all
select 4 col from dual
select sum(col) from
select col
, row_number() over (order by col) rn
from t
where rn > (select &n from dual) and rn <= (select count(*) from t) - &nEdited by: AlexAnd on Apr 27, 2011 12:37 AM -
Query to find Items in the 'Sales and Marketing' category set.
Hi,
Does any one have the query to view the 'Categories' and 'Items' assigned within those Categories for the 'Sales and Marketing' category set. Or do you know any other way in which I can get the Catalog hierarchy along with the items assigned within the catalog?
Thanks,
hiten
http://india-votes.blogspot.comAnd for the second problem try:
WITH cte
AS (
SELECT OD.ProductID
,SUM(OD.Quantity) AS SoldQty
,datepart(month, O.OrderDate) AS MonthNumber
,datename(month, O.OrderDate) AS [Month Name]
FROM dbo.Orders O
INNER JOIN dbo.[Order Details] OD ON O.OrderID = OD.OrderID
WHERE O.OrderDate >= '19970101'
AND O.OrderDate < '19980101'
GROUP BY datepart(month, O.OrderDate)
,datename(month, O.OrderDate)
,OD.ProductID
,cte1
AS (
SELECT P.ProductName
,P.ProductID
,cte.SoldQty
,cte.MonthNumber
,cte.[Month Name]
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty
) AS RnMin
,ROW_NUMBER() OVER (
PARTITION BY cte.MonthNumber ORDER BY SoldQty DESC
) AS RnMax
FROM cte
INNER JOIN dbo.Products P ON cte.ProductID = P.ProductID
SELECT [Month Name]
,MIN(CASE
WHEN RnMin = 1
THEN ProductName
END) AS [Least Sold Product]
,MIN(CASE
WHEN RnMin = 1
THEN SoldQty
END) AS [Least Sold Qty]
,MIN(CASE
WHEN RnMax = 1
THEN ProductName
END) AS [Best Sold Product]
,MIN(CASE
WHEN RnMax = 1
THEN SoldQty
END) AS [Best Sold Qty]
FROM cte1
GROUP BY [MonthNumber]
,[Month Name]
ORDER BY [MonthNumber]
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to get the first friday of the MARCH and SEPTEMBER month of any year...
Hello-
How can we get the first FRIDAY of MARCH and SEPTEMBER month for any given year.
Any help would be appreciate!
Thanks,
NikhilHi,
Please use the following function to get first fiday of any month, we have to pass month,year as varchar2 as input to this function and it will return the
date in char format, we can convert it to date.
CREATE OR REPLACE FUNCTION find_fri
(p_month VARCHAR2,
p_year VARCHAR2)
RETURN VARCHAR2 AS
p_friday VARCHAR2(15);
BEGIN
SELECT (CASE triM(TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy'),'DAY')) WHEN 'MONDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+4 ,'DD-MM-RRRR')
WHEN 'TUESDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+3 ,'DD-MM-RRRR')
WHEN 'WEDNESDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+2 ,'DD-MM-RRRR')
WHEN 'THURSDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+1 ,'DD-MM-RRRR')
WHEN 'FRIDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy'),'DD-MM-RRRR')
WHEN 'SATURDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+6,'DD-MM-RRRR')
WHEN 'SUNDAY' THEN TO_CHAR(TO_DATE(p_month||'-'||p_year,'mm-yyyy')+5 ,'DD-MM-RRRR')
ELSE 'OTHER'
END) INTO p_friday FROM dual;
RETURN p_friday;
END; -
Query to find universe modified date and modified by
Hi,
Is there a way we can query to find universe last modified by and modified date?.
I was not able to find a field to pull "modified by" info.
ThanksSreedhar,
I'm not exactly sure how you're going to get from Point "A" to Point "B", but here are the two points:
a) using QB you can perform a search as was specified in my last posting, which you point out only provides "owner"
b) if you have the Auditor portion running, then in the Audit_Detail table is the column "Detail_Type_ID" and each time a universe is accessed a code "2" is recorded and Detail_Text is loaded with the Universe name. If you join the Audit_Detail table to the Audit_Event table on Event_ID, then you'll have access to User_name and Start_Timestamp, which will show you who and when a Universe was accessed.
Thanks,
John -
I have a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".
USE [Runtime]
GO
/****** Object: UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt] Script Date: 06/11/2013 08:47:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)
-- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion
RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)
AS
BEGIN
-- Crea el Cursor
DECLARE cursorHora CURSOR
READ_ONLY
FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')
-- Declaracion de variables locales
DECLARE @produc_opt_hora int
DECLARE @produc_opt_parc int
DECLARE @nsacos int
DECLARE @time_parc datetime
-- Inicializamos VARIABLES
SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))
-- Abre y se crea el conjunto del cursor
OPEN cursorHora
-- Comenzamos los calculos
FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
/************ BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR ************/
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status = -2)
BEGIN
-- Terminamos la ejecucion
BREAK
END
-- REALIZAMOS CÁLCULOS
SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))
-- INSERTAMOS VALORES EN LA TABLA
INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)
-- Avanzamos el cursor
FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
END
/************ FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR ***************/
-- Cerramos el cursor
CLOSE cursorHora
-- Liberamos los cursores
DEALLOCATE cursorHora
RETURN
ENDYou can search the forums for that error message and find previous discussions - they all boil down to the same problem. Somewhere in your query that calls this function, the code invoked implicitly converts from string to date/datetime. In general,
this works in any version of sql server if the runtime settings are correct for the format of the string data. The fact that it works in one server and not in another server suggests that the query executes with different settings - and I'll assume for
the moment that the format of the data involved in this conversion is consistent within the database/resultset and consistent between the 2 servers.
I suggest you read Tibor's guide to the datetime datatype (via the link to his site below) first - then go find the actual code that performs this conversion. It may not be in the function you posted, since that function also executes other functions.
You also did not post the query that calls this function, so this function may not, in fact, be the source of the problem at all.
Tibor's site
Maybe you are looking for
-
Setting up a Dual Band (2.4 GHz and 5 GHz) Network
My setup: cable modem, 2 gigabyte switch, N router, G router (non apple). I would like to set a separated band network to prevent the slow down of my N network by G users. I have read the recent DesigningAirPortExtreme802.11nNetworks.pdf apple releas
-
AirtPort is not listed as one of Network choices in System Prefs
I'm trying to set up a WiFi connection/network (using 2 G5 Macs and AirPort Extreme). All online instructions start with "...select AirPort in System Network Preferences.." In my Preferences it doesn't show up. All I got there are two Ethernets and F
-
I developed an enhancement to substitute one of the subscreens used in the Material Maintenance (Retail) to release some of the standard validations in the Forecast Planning subscreen. It was done by creating a copy of the Standard subcreen, and modi
-
My Font in Terminal is messed up
https://fbcdn-sphotos-c-a.akamaihd.net/ - 5111_n.jpg hai,,, i just type "colortheme" in terminal as Normal User, but font in there is look bad. i don't know how to solve this.. please,, help me.. My rc.conf HOSTNAME="arch" HARDWARECLOCK="localtime" D
-
Youtube not working on nokia Xl
HI All Pls help i have downloaded lastest apk for youtube but its not supporting the device Pls help.... not able to use youtube