Skip to content Skip to sidebar Skip to footer

Having Trouble Creating A View In Microsoft Sql Server Management Studio

I'm new to sql and am struggling to make a view. This works and pulls in the correct data I need as a table, but when I try it as a view I get the error: SQL text cannot be repres

Solution 1:

The following article talks about how complex queries cannot be interpreted by the view designer.

Open a new query window and copy and paste the following text and execute:

CREATEVIEW MyViewName
ASSELECT [Data_Collector_ID],
           [Batch_Info_ID],
           [AssetTag],
           [DateTimeStamp],
           [Dust_Collector_DP]
    FROM (
        SELECT [Data_Collector_ID],
               [Batch_Info_ID],
               [AssetTag],
               [DateTimeStamp],
               [Dust_Collector_DP],
               ROW_NUMBER() OVER (PARTITIONBY [Batch_Info_ID] ORDERBY [DateTimeStamp] DESC) rn
        FROM [PLCLogging].[dbo].[Coater_Data_Collector]
    ) tmp
    WHERE rn =1AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
        OR rn =2AND ([DateTimeStamp] > DATEADD(DAY, -7, GETDATE()))
    ORDERBY DateTimeStamp DESC

Post a Comment for "Having Trouble Creating A View In Microsoft Sql Server Management Studio"