Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final SessionImpl sess = (SessionImpl) this.getSessionFactory().openSession();
- try (Connection conn = sess.connection(); Statement st = conn.createStatement();) {
- final NamedParameterPreparedStatement ps = NamedParameterPreparedStatement.createNamedParameterPreparedStatement(conn, aStringWithTheRequestBelow);
- // ... set parameters here ...
- ps.setQueryTimeout(15);
- final ResultSet rs = ps.executeQuery();
- } catch (final SQLException ex) {
- LOG.error("parameter 1 :" + parameter1 + "etc.");
- } finally {
- sess.close();
- }
- --DECLARE @date as DATE = '2017-09-03'; -- one of the input parameter set up from java.
- IF OBJECT_ID('tempdb.dbo.#MATCHINGDAYS718567154','U') is not null
- DROP TABLE #MATCHINGDAYS718567154; -- RANDOM TOKEN HERE TO AVOID CONCURRENCY
- WITH startDateTable AS (
- SELECT TOP 1 a.dateStart
- FROM someSelection
- ),
- endDateTable AS (
- SELECT TOP 1 endDate
- FROM anotherSelection
- ),
- AllDays AS (
- SELECT myFunc_getMaxDate(DATEADD(DAY,1,startDateTable.dateStart), DATEADD(dd, -30,@date))AS [Date]
- FROM startDateTable
- UNION ALL
- SELECT
- DATEADD(DAY, 1, [Date])
- from AllDays
- join endDateTable on 1=1
- WHERE [Date] < myFunc_getMinDate(DATEADD(dd, +7, @date),endDateTable.endDate))
- -- build a temporary table with all days from startDate to endDate the recursive way
- -- with a min -30 days before input date and 7 days after output date
- SELECT [Date]
- INTO #MATCHINGDAYS718567154
- FROM AllDays
- OPTION (MAXRECURSION 37)
- SELECT
- manyFields
- from MainTable
- -- various joins
- join #MATCHINGDAYS718567154 as MD on 1 = 1
- where 1 = 1
- and -- etc... many clauses including some computed over MATCHINGDAYS718567154
- order by someField
- DROP TABLE #MATCHINGDAYS718567154
Add Comment
Please, Sign In to add comment