質問

だから選択テーブルのグループにより、月、日、年の でのみを返す行の記録と輸出の組み合わせなく記録で表示され、一目毎日月は活動きを見て、日付の列の積極的のためのギャップがあります。かつては行毎日/月/年ない場合でもデータが存在し、T-SQL?

役に立ちましたか?

解決 2

私は開発者 に戻ってきましたの英語で分からいないところコード字に変換文字がStackOverflowた難号化に努--無数のテーブルが必要です。の例が複雑になる南青山のイチョウ並木そばにある別のテーブルからのコード例ではまっています。

declare @career-fair-id int 
select @career-fair-id = 125

create table #data ([date] datetime null, [cumulative] int null) 

declare @event-date datetime, @current-process-date datetime, @day-count int 
select @event-date = (select careerfairdate from tbl-career-fair where careerfairid = @career-fair-id) 
select @current-process-date = dateadd(day, -90, @event-date) 

    while @event-date <> @current-process-date 
    begin 
    select @current-process-date = dateadd(day, 1, @current-process-date) 
    select @day-count = (select count(*) from tbl-career-fair-junction where attendanceregister <= @current-process-date and careerfairid = @career-fair-id) 
        if @current-process-date <= getdate() 
        insert into #data ([date], [cumulative]) values(@current-process-date, @day-count) 
    end 

    select * from #data 
    drop table #data 

他のヒント

カレンダーを作成するテーブルの外で参加できるテーブル

見を 番号テーブル.ができhackishで最良の方法だより迅速にクエリデータの欠落、またはすべて、または何がしたい値を調べ範囲内かどうかにかかわらず、すべての値がその範囲を使用します。

私SQLMenaceとしてお使いいただけますCROSS JOINを迅速に読み込みのテーブルを作成します。
http://www.sitepoint.com/forums/showthread.php?t=562806

タスクのための完全なセット日を左に入にデータなど


DECLARE @StartInt int
DECLARE @Increment int
DECLARE @Iterations int

SET @StartInt = 0
SET @Increment = 1
SET @Iterations = 365


SELECT
    tCompleteDateSet.[Date]
  ,AggregatedMeasure = SUM(ISNULL(t.Data, 0))
FROM
        (

            SELECT
                [Date] = dateadd(dd,GeneratedInt, @StartDate)
            FROM
                [dbo].[tvfUtilGenerateIntegerList] (
                        @StartInt,
                        ,@Increment,
                        ,@Iterations
                    )
            ) tCompleteDateSet
    LEFT JOIN tblData t
          ON (t.[Date] = tCompleteDateSet.[Date])
GROUP BY
tCompleteDateSet.[Date]

のテーブル値関数tvfUtilGenerateIntegerListに定義される


-- Example Inputs

-- DECLARE @StartInt int
-- DECLARE @Increment int
-- DECLARE @Iterations int
-- SET @StartInt = 56200
-- SET @Increment = 1
-- SET @Iterations = 400
-- DECLARE @tblResults TABLE
-- (
--     IterationId int identity(1,1),
--     GeneratedInt int
-- )


-- =============================================
-- Author: 6eorge Jetson
-- Create date: 11/22/3333
-- Description: Generates and returns the desired list of integers as a table
-- =============================================
CREATE FUNCTION [dbo].[tvfUtilGenerateIntegerList]
(
    @StartInt int,
    @Increment int,
  @Iterations int
)
RETURNS
@tblResults TABLE
(
    IterationId int identity(1,1),
    GeneratedInt int
)
AS
BEGIN

  DECLARE @counter int
  SET @counter= 0
  WHILE (@counter < @Iterations)
    BEGIN
    INSERT @tblResults(GeneratedInt) VALUES(@StartInt + @counter*@Increment)
    SET @counter = @counter + 1
    END


  RETURN
END
--Debug
--SELECT * FROM @tblResults

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top