-2

質問があります:

複数のクエリを 1 つのクエリにまとめることはできますか?

つまり、フォームには次のような 10 個のクエリがあります。

1.  SELECT ThisValue FROM thatTable1 WHERE
2.  SELECT ThisValue FROM thatTable2 WHERE
                 .......
10.      SELECT ThisValue FROM thatTable10 WHERE

Access のどこにこのコードを記述すればよいでしょうか。

CREATE PROC dbo.proc_app_CollectControlData
AS
    SET NOCOUNT ON

    DECLARE @t TABLE
    (
      CONTROLNAME   nvarchar(74),
      CONTROLVALUE  nvarchar(255)
    )

    -- Now we collect the data for the 10 different controls
    INSERT INTO @t
    (CONTROLNAME, CONTROLVALUE)
    SELECT 'MyFirstControl',
            ThisValue
    FROM dbo.ThatTable
    WHERE Condition1

    ...

    INSERT INTO @t
    (CONTROLNAME, CONTROLVALUE)
    SELECT 'MyTenthControl',
            ThisValue
    FROM dbo.ThatTable
    WHERE Condition10

    -- And now we return all found data to the client
    SELECT * FROM @
    SET NOCOUNT OFF
GO
4

2 に答える 2

3
SELECT ThisValue FROM thatTable1 WHERE ...
UNION ALL
SELECT ThisValue FROM thatTable2 WHERE ...
UNION ALL
SELECT ThisValue FROM thatTable10 WHERE ...
于 2012-05-21T10:02:49.620 に答える
3

UNION Operatorを探していると思います。

SELECT  'MyFirstControl' AS ControlName, ThisValue AS ControlValue
FROM    thatTable1 
WHERE   Condition1 
UNION ALL
SELECT  'MySecondControl' AS ControlName, ThisValue AS ControlValue
FROM    thatTable2
WHERE   Condition2
UNION ALL
SELECT  'MyThirdControl' AS ControlName, ThisValue AS ControlValue
FROM    thatTable3
WHERE   Condition3
于 2012-05-21T10:03:33.403 に答える