0

以下はmtデータベーステーブルです

CREATE TABLE [dbo].[mtblLog_Book](
[Logbook_Number] [int] IDENTITY(1,1) NOT NULL,
[Sno] [int] NULL,
[Vehicle_Number] [nvarchar](100) NULL,
[Vehicle_Booking_Date] [datetime] NULL,
[Time_From] [datetime] NULL,
[Time_To] [datetime] NULL,
[KM_Start] [int] NULL,
[KM_End] [int] NULL,
[Total] [int] NULL,
[Vehicle_Used_By] [varchar](100) NULL,
[Cost_Code] [nvarchar](50) NULL,
[Budget_Line] [nvarchar](50) NULL,
[Entry_Date] [datetime] NULL
) ON [PRIMARY]

重複がありますCost_Code。以下の形式でデータを取得できるようにクエリが必要です

CostCode1
......................
All data which belong to CostCode1
......................

CostCode2
......................
All data which belong to CostCode2
......................

CostCode3
......................
All data which belong to CostCode3
......................

続き....コストコードへ* n *

ありがとう

4

2 に答える 2

1

上記のように表示したい場合は、このコードを使用してください。

    protected void show()
    {
     Response.Clear();
     string sql = "select Cost_Code from mtblLog_Book";
     ds = obj.openDataset(sql, schoolCode);

     if (ds.Tables[0].Rows.Count == 0)
     {
        Response.Write("[{\"Records\":\"" + "NA" + "\"}]");
     }
     else
     {
        int i;
        string output;
        for (i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
        {
        string sqlOutput ="Select * from mtblLog_Book where CostCode='"+ds.Tables[0].Rows[i][ "CostCode"].ToString()+ "';";
            Dataset dsOutPut= new Dataset;
          output = "[{\" Logbook_Number \":\"" +dsOutPut.Tables[0].Rows[i]["Logbook_Number"].ToString() + "\",\" Sno\": \"" + dsOutPut.Tables[0].Rows[i][" Sno"] + "\",\" Vehicle_Number\": \"" + dsOutPut.Tables[0].Rows[i][" Vehicle_Number"].ToString() + "\",\" Vehicle_Booking_Date\": \"" + dsOutPut.Tables[0].Rows[i][" Vehicle_Booking_Date"].ToString() + "\" }]"

            Response.Write(output);
            if (i < dsOutPut.Tables[0].Rows.Count - 1)
            {
                Response.Write("\n");
            }
        }
      }
    }
于 2013-03-22T11:25:03.987 に答える
0

SQL ServerとSSMSを使用している場合は、結果をテキストに出力するように設定して、次のような操作を行うことができます。

DECLARE @costCode NVARCHAR(50)

DECLARE cur CURSOR FOR
SELECT DISTINCT Cost_Code
FROM dbo.mtblLog_Book

OPEN cur
FETCH NEXT FROM cur INTO @costCode
WHILE @@FETCH_STATUS=0
BEGIN
    PRINT @costCode
    PRINT '......................................'
    SELECT * FROM dbo.mtblLog_Book
    WHERE Cost_Code = @costCode
    PRINT '......................................'
              PRINT ''  
END

CLOSE cur
DEALLOCATE cur

次に、結果をコピーして、必要な場所に貼り付けます

于 2013-03-22T10:11:43.557 に答える