Paul Linton
Sunday, June 30, 2013
MVC in Visual Studio 2013 Preview
Why is ORDER BY allowed in TVF but not in INLINE TVF?
There must be a real simple explanation which escapes me right now. Thanks.
Does it mean I can trick the database engine? Use TVF with ORDER BY instead of ITVF?
CREATE FUNCTION Sales.ufn_SalesByStore (@storeid int)
RETURNS @Sales TABLE (ProdID int, Name varchar(50), Total money)
AS
BEGIN INSERT @Sales
SELECT P.ProductID, P.Name, SUM(SD.LineTotal) AS 'Total'
FROM Production.Product AS P
JOIN Sales.SalesOrderDetail AS SD ON SD.ProductID = P.ProductID
JOIN Sales.SalesOrderHeader AS SH ON SH.SalesOrderID = SD.SalesOrderID
JOIN Sales.Customer AS C ON SH.CustomerID = C.CustomerID
WHERE C.StoreID = @storeid
GROUP BY P.ProductID, P.Name
ORDER BY P.ProductID, P.Name;
RETURN ;
END
GO
CREATE FUNCTION Sales.ufn_SalesByStore1 (@storeid int)
RETURNS TABLE
AS
RETURN
(
SELECT P.ProductID, P.Name, SUM(SD.LineTotal) AS 'Total'
FROM Production.Product AS P
JOIN Sales.SalesOrderDetail AS SD ON SD.ProductID = P.ProductID
JOIN Sales.SalesOrderHeader AS SH ON SH.SalesOrderID = SD.SalesOrderID
JOIN Sales.Customer AS C ON SH.CustomerID = C.CustomerID
WHERE C.StoreID = @storeid
GROUP BY P.ProductID, P.Name
ORDER BY P.ProductID, P.Name;
);
GO
/*
Msg 1033, Level 15, State 1, Procedure ufn_SalesByStore1, Line 13
The ORDER BY clause is invalid in views, inline functions, derived tables,
subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
*/
Kalman Toth Database & OLAP Architect sqlusa.com
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Why is ORDER BY allowed in TVF but not in INLINE TVF?
ORDER BY is always permitted when you insert into a table, alhough it does not mean anything unless the table has a target table has an IDENTITY column or a column with default of NEXT VALUE FOR (SQL 2012 only).
Thus, in the example you cannot trick anything. The Database Engine is free to completely ignore your ORDER BY clause.
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Why is ORDER BY allowed in TVF but not in INLINE TVF?
Joe,
Trouble with VIEWs that they don't take parameters.
Consider INLINE TABLE-VALUED function as a view with parameters:
/******** INLINE table-valued user-defined function ***********/
CREATE FUNCTION ufnSalesByCountry (@CountryTerritory varchar(60))
RETURNS TABLE AS
RETURN
SELECT TOP 1000 [SalesPersonID]
,[FullName]
,[JobTitle]
,[SalesTerritory]
,[2006]
,[2007]
,[2008]
FROM [AdventureWorks2012].[Sales].[vSalesPersonSalesByFiscalYears]
WHERE SalesTerritory = @CountryTerritory;
GO
SELECT * FROM ufnSalesByCountry('Germany');
GO
/*
SalesPersonID FullName JobTitle SalesTerritory 2006 2007 2008
288 Rachel B Valdez Sales Representative Germany NULL NULL 1827066.7118
*/
Kalman Toth Database & OLAP Architect sqlusa.com
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
speech-to-text without a dictionary or grammar using c# ?
In windows 8.1 there is an text to speech api
http://code.msdn.microsoft.com/windowsapps/Speech-synthesis-sample-6e07b218
for windows 8 you would need to use something like this
http://translatorservice.codeplex.com/
Visual Studio throws an exception: "Object reference not set to an instance of an object."
This line asumes that mSpriteTexture has been set. This is propably not the case.Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2
Well if I remove the line it starts perfectly (but I still think it's important) any suggestions?
I LOVE VISUAL STUDIO ULTIMATE 2012!!! (Since I was coding with the express versions, now when I have the brand new one it's great!
Visual Studio throws an exception: "Object reference not set to an instance of an object."
What do you mean "I think it is important". Either you need the line/Size or you need it not. There is no "maybe" in Programming.
From the code you showed us, the Reactangle Size has no meaning at all. It seems to store the precalculated Scaled Size of the texture, but it is never used. The Rendering Engine just takes the Texture and the Scale, not Size.
What makes it even less understandable, is that you have this line in two different places:
Once in Scale.Set()
Once in LoadContent()
The one in Scale.Set() could fail because there is no Texture loaded (yet).
The one in LoadContent() could fail when "theContentManager.Load<Texture2D>(theAssetName);" returns null.
Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2