sql - Trouble with Pivot Tables -


I know that there are a lot of pivot table examples on the internet, although I'm new to SQL and I am having trouble Is a bit because all the examples seem related to the overall work.

  Table 1: | Date | Tag | Price | | 06/10 2:00 a.m. 65 | | 06/10 2:00 pm b. 44 | | 06/10 2:00 p.e. 33 | | 06/10 2:02 p.m. | A. 12 | | 06/10 2:02 p.m. | B 55 | | 06/10 2:02 p.m. | C. 21 | .... 06/10 1:58 am | A. 23   

I want to see it (Table 2):

  | Date | A. B C. | 06/10 2:00 pm 65 | 44 | 33 | 06/10 2:02 PM 12 | 55 | 21 | ..... 06/10 1:58 am 23 | e.t.c. | e.t.c. |   

(sorry for format)

There are some issues that encounter (which does not work with the code I got online) A SQL job), every 2 minutes so that this figure from Table 1 is being constantly moved into 2 tables. Still I think that I will need to change the date of each time? (The syntax I have seen is that the pivot table itself seems simple in itself, but the datetime is giving me pain.

Smoke itself sounds simple: , [B], [C]) p < For table of smoke (select) (minimum)

for the stored procedure, I saved it in table 2 as a filter in Table 2 for / code>

  tag. Will use the end date, except the incomplete group (I'm assuming, at some point, all three tags will be present, and this can only be the last date  

then in the code:

  set enterprovitted tag set nunca Create Started Transactions in XACT_ABORT Start the transaction @startDate DateTime - The date of the last date or time from date 2 to date @startDate = isnull (maximum ([date]), '1753-01-01' Select Table 2 to the table 2 * Choose from the table 1 (smoke) for P in ([A], [B], [C]) where [date]> date => start date - exclude incomplete groups Is given and no one is empty and B is not zero and no transaction is removed.   

If the group can be incomplete then you should delete the exlude filter and a delim statement which removes the last date if it is incomplete, and to recover the same code three millisecond before @startDate Adjusts, but now in a more full state

Comments