sql - How to convert this query to linq -


Hello Please tell me how I can convert this query to linq, in fact I need to create a dynamic pivot table from the SQL server. I have done this query but I see this query in my SQL server or the function Or can not save as well. So I want to use linq veerion of this query in my unit mode.

tnx

  Announcement @ columns table table ([columnname] VARCHAR (50)); Insert in the @ columns ([columnname]) Select '' ['+ Convert (Nerve (50), Unit) +'] Metwaleview; Announcement @PivotColumns VARCHAR (MAX), @TotalColumn VARCHAR (Max), @SQL varchar (max); SET @PivotColumns = (XML path ('') for @ columns from SELECT STUFF (SELECT DISTINCT ',' + CONVERT (nvarchar (50), [ColumnName]) column), 1, 2, ''); SET @ TotalColumn = (SELECT STIFF ('SELECT DISTINCT' + ISNULL ('+ CONVERT (nvarchar (50), [ColumnName] +', 0) From 'column to column' XML path ('')), 1, 3, T 'pwat (max ([value]);); SET = sql =' select *, ('+ + total column +') from AS [total] (serial), [unit], [value] ) [Unit] IN ('+ @ pivot column' ')) ASP;' EXEC (@ SQL)  

I find that in a simple way Can be used by the shop process Linq and etc. To achieve this objective:

  to see Proc Process Metals Start Column Table Tables [[Column]] VARCHAR (50)) Insert in the columns @ ([columnname]) Select '' ['+ Convert (nerve (50), unit) +'] 'to db. Metwaleview; Declaration @PivotColumns VARCHAR (MAX), @TotalColumn VARCHAR (Max ), @ Sql varchar (max); SET @PivotColumns = (XML path ('') for @ columns from SELECT STUFF (SELECT DISTINCT ',' + CONVERT (nvarchar (50), [ColumnName]) column), 1, 2, ''); SET @ TotalColumn = (SELECT STIFF ('SELECT DISTINCT' + ISNULL ('+ CONVERT (nvarchar (50), [ColumnName] +', 0) From 'column to column' XML path ('')), 1, 3, T 'pwat (max ([value]);); SET = sql =' select *, ('+ + total column +') from AS [total] (serial), [unit], [value] ) [Unit] IN ('+ @ Pivot column +')) ASP; 'EXEC (@ SQL) END  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -