spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

T-SQL Help Needed in Converting an Appointment List into a Master Schedule


What you need is indeed a Dynamic Pivot. If the Appointments table looks like the following

CREATE TABLE Appointments
(
   ApptDatetime DATETIME,
   Staffname VARCHAR (50),
   ApptLength INT
)

Then the following will work:

DECLARE @ColumnList VARCHAR (MAX)
DECLARE @SQL VARCHAR(MAX)

-- Create a list of distinct Staffnames which will
become column headers
SELECT @ColumnList = COALESCE(@ColumnList + '],
[','[') + CAST(S.Staffname AS VARCHAR(12)) FROM
(SELECT DISTINCT Staffname FROM Appointments) S
SET @ColumnList = @ColumnList + ']'

SET @SQL = '
SELECT
  [ApptDatetime], ' + @ColumnList + '
FROM
(  
  SELECT
    A.[ApptDatetime],
    A.Staffname,
    A.ApptLength
  FROM
      Appointments A
  WHERE
    A.[ApptDateTime] BETWEEN GETDATE() AND
DATEADD(DAY, 7, GETDATE())   
)  T
PIVOT
(
    MIN(ApptLength)
    FOR T.Staffname IN (' + @ColumnList + ')
) AS PVT'
--PRINT @SQL
exec (@SQL)

Categories : SQL

Related to : T-SQL Help Needed in Converting an Appointment List into a Master Schedule
PostgreSQL master-slave replication redirecting writes to master
You cannot! PostgreSQL does not have the ability to redirect writes to master node, hence the slave will only accept read-only transactions. One tool that acts as a middleware and can do load balancing of read-only statements between master and the slaves, but also redirecting write commands/transactions to master is PgPool-II. If you can make your application to differentiate (through different

Categories : Postgresql
Local master branch out of tune from remote master
What conflicts does it show? If you are using a tool, it is probably doing a git pull before doing a git push and that is what is causing the issue. If you can help it always use a terminal to run git commands.

Categories : GIT
What is the best way to create a parent/master entry in a DJANGO CRUD database app and then add associating data fields to the parent/master?
No. You don't need multiple barcode models. The fact that you have a ForeignKey from barcode to hardware already allows you to have multiple barcodes for each hardware: a ForeignKey defines a many-to-one relationship. Also, it doesn't make any sense to name the foreignkey after the model it is in: it needs to be named for the model it is pointing to, ie hardware. Finally, don't prefix your field n

Categories : Python
Error converting data type varchar to varbinary. MSSQL when converting to Integer
Hex always have two characters. Try this create table hexvalue(Data varchar(10)) insert into hexvalue values('05'),('0E'),('12'),('17'),('15'),('EF'),('EF') select convert(int, convert(varbinary, '0x'+Data, 1)) from hexvalue

Categories : Sql Server
Is there a way to schedule html changes?
Short answer: no. Long answer: Yes, of course. But you will either have to use a server side scripting language which generates your HTML for you and based on dates, will render different things, or, create a "dynamic" HTML page using a client side script such as Javascript. Javascript allows you to create "live" pages, which can change their behaviour based on numerous variables, such as the c

Categories : HTML
Recently Add
SQL command to insert two primary keys into third table
How to do a registerform by ASP.NET VB SQL
Shortest time and trip between two stops across many trip options (GTFS)
Using IN and EXISTS subquery with AND operation instead of OR?
How to select multiple alias columns from the same table
Delete records from a given table
date manipulation in postgresql
PSQL query with join query from a db newbie
Protect LocalDB from user access
Update field with combined contents from other fields
SQL select unique records under certain priority and conditions from multiple columns
Multiply quantities for all parent child relationships
I'm having an issue running a query from a batch file
Concatenate strings while filtering by another column in SQL Server view
Parsing Dynamic XML to SQL Server tables with Parent and child relation
Using MERGE for delete and insert in oracle
how to display the pre value and post value of a column after updating it?
sql loop to fill up date between two time stamps
With SQL/TSQL, how can I use STUFF within this WHILE clause?
Challenging db table and query
Query to fetch row corresponding to Max value in SQL
Oracle SQL - ORA-00936 on DATE()
how to split single row into multiple row in db2?
Combine fields into one column
How can I perform an SQl where query then list properly?
SQL - Selection of the oldest order for every customer (join two tables)
Sum two counts in a new column without repeating the code
Creating multiple sum fields based upon criteria in another field in MS access 2007
Grouping by two values in same table
MS SQL last record
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.