Buscar contenidos

martes, 30 de marzo de 2021

SQL SERVER – Select Columns from Stored Procedure Resultset


 https://blog.sqlauthority.com/2013/09/26/sql-server-select-columns-from-stored-procedure-resultset/



First we will create a sample stored procedure.

1
2
3
4
5
6
CREATE PROCEDURE SampleSP
AS
SELECT 1 AS Col1, 2 AS Col2
UNION
SELECT 11, 22
GO

Now we will create a table where we will temporarily store the result set of stored procedures. We will be using INSERT INTO and EXEC command to retrieve the values and insert into temporary table.

1
2
3
4
5
CREATE TABLE #TempTable (Col1 INT, Col2 INT)
GO
INSERT INTO #TempTable
EXEC SampleSP
GO

Next we will retrieve our data from stored procedure.

1
2
3
SELECT *
FROM #TempTable
GO

Finally we will clean up all the objects which we have created.

1
2
3
DROP TABLE #TempTable
DROP PROCEDURE SampleSP
GO

Let me know if you want me to share such back to basic tips.

Cómo concatenar subconsultas en un solo campo con SQL Server

 https://www.campusmvp.es/recursos/post/como-concatenar-subconsultas-en-un-solo-campo-con-sql-server.aspx


http://chancrovsky.blogspot.com/2013/04/concatenar-usando-for-xml-path-y-stuff.html


SELECT ', ' + Categorias.Categoria FROM Categorias INNER JOIN ProductosCategorias ON ProductosCategorias.idCategoria = Categorias.idCategoria WHERE ProductosCategorias.idProducto = 4 FOR XML PATH ('')



SELECT STUFF( (SELECT ', ' + Categorias.Categoria FROM Categorias INNER JOIN ProductosCategorias ON ProductosCategorias.idCategoria = Categorias.idCategoria WHERE ProductosCategorias.idProducto = 4 FOR XML PATH ('')), 1,2, '')

lunes, 22 de marzo de 2021

Convertir HTML a PDF con wkhtmltopdf



Para los desarrolladores web, es mucho más fácil crear un PDF a partir del formato HTML, básicamente porque proporciona una mejor opción para administrar el PDF. Para esta tarea, los desarrolladores web utilizan bibliotecas como wkhtmltopdf. wkhtmltopdf es una herramienta de línea de comandos para convertir HTML en PDF utilizando el motor de renderizado QT Webkit.

OpenHtmlToPdf

.NET library for rendering HTML documents to PDF format.

OpenHtmlToPdf uses WkHtmlToPdf native Windows library for HTML to PDF rendering.

Download

OpenHtmlToPdf can be download as a [NuGet package] (https://www.nuget.org/packages/OpenHtmlToPdf/)

Usage

Generate PDF with default settings

const string html =

"<!DOCTYPE html>" +

"<html>" +

"<head><meta charset='UTF-8'><title>Title</title></head>" +

"<body>Body text...</body>" +

"</html>";

var pdf = Pdf

.From(html)

.Content();

Defining fluent settings

const string html =

"<!DOCTYPE html>" +

"<html>" +

"<head><meta charset='UTF-8'><title>Title</title></head>" +

"<body>Body text...</body>" +

"</html>";


var pdf = Pdf

.From(html)

.OfSize(PaperSize.A4)

.WithTitle("Title")

.WithoutOutline()

.WithMargins(1.25.Centimeters())

.Portrait()

.Comressed()

.Content();

Defining wkhtmltopdf settings directly

Settings API documentation

const string html =

"<!DOCTYPE html>" +

"<html>" +

"<head><meta charset='UTF-8'><title>Title</title></head>" +

"<body>Body text...</body>" +

"</html>";


var pdf = Pdf

.From(html)

.WithGlobalSetting("orientation", "Landscape")

.WithObjectSetting("web.defaultEncoding", "utf-8")

.Content();


Recursos:

 https://github.com/codaxy/wkhtmltopdf

https://github.com/vilppu/OpenHtmlToPdf

https://parzibyte.me/blog/2019/10/29/convertir-html-pdf-wkhtmltopdf/

https://blog.aspose.com/2020/02/28/convert-html-to-pdf-programmatically-in-csharp-net/


Pasos para configurar Azure+VM+FTP

→Crear en Azure FTP, según el tier requerido...

→Componentes requeridos para un FTP:

  • FTP_VNET          |  Virtual network
  • FTPVM                |  Virtual machine
  • FTPVM-nic          |  Network interface
  • FTPVM-nsg         |  Network security group
  • FTPVM-osdisk    |  Disk
  • FTPVM-pip         |  Public IP address
  • ftpvmstorage0f5  |  Storage account



→Virtual machine > Networking 

→VM > Add Features>
  • WebServer (IIS)
  • FTP Server
→VM > IIS FTP Setting


→VM > Restart Microsoft FTP Service




→VM > FileZilla Server >



Short summary of what can fix this issue. Worked for me.

  1. Azure VM - Firewall

    1.1) Open Inbound port 21

    1.2) Open few Inbound ports for Passive mode - Say 1035 to 1040

  2. Azure VM - FileZilla Server

    2.1) In settings - Change Passive ports to 1035 to 1040 ( or what ever ports you opened in 1.2 above )

    2.2) For "External Server IP" option, use "Retrieve external IP address from"

  3. Azure Control Panel - Endpoints

    3.1) Open port 21, and 1035 to 1040 ( or what ever ports you opened in 1.2 above )


→ VM > FileZilla Server > 
  • User Add
  • Shared folder Add



→VM > Revisar Firewall Inbound con el rango de puertos selecionados

→Recursos:

https://www.youtube.com/watch?v=J6IJ7JPAuN8
https://serverfault.com/questions/527322/problems-configuring-filezilla-ftp-server-on-windows-azure-virtual-machine
https://docs.microsoft.com/en-us/azure/connectors/connectors-create-api-ftp