jueves, 25 de mayo de 2023

Using FOR XML PATH

 https://www.sqlmatters.com/Articles/Converting%20row%20values%20in%20a%20table%20to%20a%20single%20concatenated%20string.aspx

Solution 5 : Using FOR XML PATH

Some of the XML statements introduced in SQL Server 2005 had to implement a means of looping around data in order to produce XML. This solution takes advantage of this, but strips out the XML specific parts to produce the comma separated list.
SELECT STUFF((SELECT ',' + Txt
            FROM ConcatenationDemo
            FOR XML PATH('')) ,1,1,'') AS Txt

martes, 23 de mayo de 2023

sql server separar cadenas

CREATE FUNCTION [dbo].[SepararCadena](@cadena      NVARCHAR(MAX),  

                                     @delimitador CHAR(1))  

RETURNS @output TABLE(splitData NVARCHAR(MAX))  

AS  

     BEGIN  

         DECLARE @start INT  

         DECLARE @end INT  

         SELECT @start = 1,  

                @end = CHARINDEX(@delimitador, @cadena)  

         WHILE @start < LEN(@cadena) + 1  

             BEGIN  

                 IF @end = 0  

                     SET @end = LEN(@cadena) + 1  

                 INSERT INTO @output(splitData)  

                 VALUES(SUBSTRING(@cadena, @start, @end-@start))  

                 SET @start = @end + 1  

                 SET @end = CHARINDEX(@delimitador, @cadena, @start)  

             END  

         RETURN  

     END  

jueves, 30 de marzo de 2023

generar int id compuesto sql server

 CREATE TABLE [dbo].[Tabla1](

[Id] [varchar](10) NOT NULL,

[Descripcion] [varchar](50) NOT NULL,

[Activo] [bit] NOT NULL,

[ParentId]  AS (CONVERT([int],left([id],charindex('.',[id]+'.')-(1)),0))

)

##

CREATE PROCEDURE [dbo].[GENERAR_ID_COMPUESTO] @idNuevo AS INT  

AS  

    BEGIN  

        DECLARE @id AS VARCHAR(20);  

        SET @id= CONVERT(VARCHAR(10), @idNuevo) + '.' + CONVERT(VARCHAR(20),  

        (  

            SELECT ISNULL(MAX(CONVERT(INTEGER, (CASE  

                                                    WHEN(LEN(Id) - LEN(REPLACE(Id, '.', ''))) = 1  

                                                    THEN SUBSTRING(Id, PATINDEX('%.%', Id) + 1, LEN(Id))  

                                                    WHEN(LEN(Id) - LEN(REPLACE(Id, '.', ''))) = 2  

                                                    THEN SUBSTRING(Id, PATINDEX('%.%', Id) + 1, PATINDEX('%.%', (SUBSTRING(Id, PATINDEX('%.%', Id) + 1, LEN(Id)))) - 1)  

                                                    ELSE 0  

                                                END))), 1) + 1  

            FROM Tabla1 

            WHERE(CASE  

                      WHEN(LEN(Id) - LEN(REPLACE(Id, '.', ''))) = 0  

                      THEN Id  

                      WHEN(LEN(Id) - LEN(REPLACE(Id, '.', ''))) > 0  

                      THEN SUBSTRING(Id, 0, PATINDEX('%.%', Id))  

                      ELSE 0  

                  END) = @idNuevo  

                 AND (CASE  

                          WHEN(LEN(Id) - LEN(REPLACE(Id, '.', ''))) = 2  

                          THEN REVERSE(SUBSTRING(REVERSE(Id), 0, PATINDEX('%.%', REVERSE(Id))))  

                          ELSE 0  

                      END) = 0  

        ));  

        SELECT @id;  

    END;  

##

--example

DECLARE @id as NUMERIC(18,0)      

EXECUTE Ceres.dbo.SYNC_GENERAR_NAVEID 23, @id OUTPUT;    

-- result: 23.3

--insert into Tabla1 (id) select @id

DECLARE @id as NUMERIC(18,0)      

EXECUTE Ceres.dbo.SYNC_GENERAR_NAVEID 23, @id OUTPUT;    

-- result: 23.4

--insert into Tabla1 (id) select @id

OUTPUT sql server

In SQL Server, you can return multiple output parameters from a stored procedure using the OUTPUT keyword for each output parameter. Here is an example of how to do this:

 ALTER PROCEDURE myStoredProcedure

    @inputParam1 INT,

    @inputParam2 VARCHAR(50),

    @outputParam1 INT OUTPUT,

    @outputParam2 VARCHAR(50) OUTPUT

AS

BEGIN

    -- your stored procedure code here

    SET @outputParam1 = 12345

    SET @outputParam2 = 'Hello World'

END



DECLARE @output1 INT

DECLARE @output2 VARCHAR(50)


EXEC myStoredProcedure 1, 'input2', @output1 OUTPUT, @output2 OUTPUT


SELECT @output1 AS 'Output 1', @output2 AS 'Output 2'

viernes, 24 de marzo de 2023

Integración Git/GitHub/VS2010

 https://elprogramadorperdido.wordpress.com/2012/12/07/integracion-gitgithubvs2010/

Integración Git/GitHub/VS2010

...

  • Integrar Git con Visual Studio 2010

Para integrar Git con Visual Studio 2010 debemos descargar la extensión Git Source Control Provider bien desde el propio Visual Studio

Herramientas->Administrador de extensiones->Galería en línea buscar el paquete Git Source Control Provider

o bien desde la siguiente url:

http://visualstudiogallery.msdn.microsoft.com/63a7e40d-4d71-4fbb-a23b-d262124b8f4c

Después de haber realizado la instalación, debemos reiniciar Visual Studio 2010 e ir a Herramientas->Opciones->Source Control, y seleccionar Git Source Control Provider.

SourceControlGit_VS2010

Por último nos quedaría por instalar las Git Extensions para poder manejarnos, sin utilizar la línea de comandos Git bash.

– URL de descarga: http://code.google.com/p/gitextensions/downloads/list

solo tenemos que descargar la última versión, instalar en nuestra máquina y listo, tendremos una nueva opción en el menu principal de Visual Studio llamada GIT.

Git_VS2010en el proximo post hablaremos de las acciones: git init, git remote, git commit, git pull, git push, etc…

jueves, 23 de marzo de 2023

ejecutar multiples SP_HELPTEXT SQL Server

https://forums.sqlteam.com/t/run-sp-helptext-for-multiple-views/19791


 CREATE TABLE #text ( id int IDENTITY(1, 1) NOT NULL, text_line varchar(max) NULL );

INSERT INTO #text EXEC sys.SP_HELPTEXT store1

INSERT INTO #text EXEC sys.SP_HELPTEXT store2

jueves, 9 de febrero de 2023

SQL Server EXEC result INTO TABLE in LOOP

 


CREATE TABLE #tmp(columnName INT);  

INSERT INTO #tmp 

EXECUTE query_1 

@parameter1, 

@parameter2, 

@parameter3;

loop


CREATE TABLE #tabla

                (v6 INT, 

                 v5 VARCHAR(255), 

                 v4 VARCHAR(10), 

                 v4 INT, 

                 v3 DATETIME, 

                 v2 DATETIME, 

                 v1 VARCHAR(10)

                );

                DECLARE @Contador INT;

                SET @Contador = 0;

                WHILE(@Contador <= 10)

                    BEGIN

                        INSERT INTO #tabla

                        EXECUTE query_2

                                1, 

                                @Contador;

                        SET @Contador = @Contador + 1;

        END;

                SELECT *

                FROM #tabla;

viernes, 23 de diciembre de 2022

Embedding QR Code Scanner In Xamarin.Forms

 https://www.c-sharpcorner.com/article/embedding-qr-code-scanner-in-xamarin-forms/Dropdown in Xamarin.Forms

ZXing.Net.Mobile plugin is a useful plugin to facilitate scanning barcodes as effortlessly and painlessly as possible in our own applications works Xamarin.iOS, Xamarin.Android, Tizen, and UWP.

Library Link: https://github.com/Redth/ZXing.Net.Mobile

Without much introduction, we will skip into the coding part of this article.

Coding Part

Here, I will explain the steps to create Dropdown in Xamarin.Forms.

  • Step 1: Creating a new Xamarin.Forms Projects.
  • Step 2: Setting up the scanner in Xamarin.Forms .Net Standard Project
  • Step 3: Implementation of QR Code Scanner inside the screen/page

Step 1 - Creating new Xamarin.Forms Projects

Create New Project by Selecting New -> Project -> Select Xamarin Cross Platform App and Click OK.

Note
Xamarin.Forms version should be greater than 4.5.

Embedding QR Code Scanner in Xamarin.Forms

Then select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and click OK.

Embedding QR Code Scanner in Xamarin.Forms

Step 2 - Setting up the scanner in Xamarin.Forms .Net Standard Project

In this step, we will see how to setup the plugin.

Open the Nuget Manager in the Visual Studio Solution by right clicking the solution and select “Manage Nuget Packages”.

Then “ZXing.Net.Mobile” and check all the projects in the solution, install the plugin

Embedding QR Code Scanner in Xamarin.Forms

After the installation, we need to do some additional setup in the platform wise projects.

In Android, update the below code blocks in the MainActivity to initialize the plugin.

// In OnCreate method
Xamarin.Essentials.Platform.Init(Application);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
// In Activity to handle the camera permission from the plugin it self.
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) {
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
C#

Step 3 - Implementation of QR Code Scanner inside the screen/page

In this step, we will see how to use the view in Xamarin.Forms.

Open your designer file and in my case MainPage.xaml and add the ZxingSannerView as shown below.

<zxing:ZXingScannerView x:Name="zxing" VerticalOptions="FillAndExpand"/>
Markup

Add Label below the ZxingSannerView to see the results when the bar/QR code is scanned.

Then add the below event to know the successful scan from the control.

zxing.OnScanResult += (result) => Device.BeginInvokeOnMainThread(() => {
    lblResult.Text = result.Text;
});
C#

Full Code implementation of ZXing Scanner View in MainPage

Here, we will see the full code for Main Page.

public partial class MainPage: ContentPage {
    public MainPage() {
        InitializeComponent();
        zxing.OnScanResult += (result) => Device.BeginInvokeOnMainThread(() => {
            lblResult.Text = result.Text;
        });
    }
    protected override void OnAppearing() {
        base.OnAppearing();
        zxing.IsScanning = true;
    }
    protected override void OnDisappearing() {
        zxing.IsScanning = false;
        base.OnDisappearing();
    }
}
C#

Demo

The following screens show the output of this tutorial and it is awesome to have this dropdown in Xamarin.Forms

viernes, 16 de diciembre de 2022

datetime Sqlite

 select datetime(columnDate/10000000 - 62135596800, 'unixepoch') from tabla ;

lunes, 12 de diciembre de 2022

DATEPART sql server

   select  DATEPART(YY, getdate() ) AS Year, 

   DATEPART(QQ, getdate() ) AS Quarter, 

   DATEPART(WK, getdate() ) AS Week, 

   DATEPART(DY, getdate() ) AS dayofYear, 

   DATEPART(MM, getdate() ) AS Month, 

   DATEPART(DD, getdate() ) AS Date, 

   DATEPART(hour, getdate() ) AS Hour, 

   DATEPART(minute, getdate() ) AS Minute, 

   DATEPART(second, getdate() ) AS Second, 

   DATEPART(millisecond, getdate() ) AS Millsecond, 

   DATEPART(microsecond, getdate() ) AS Microsecond, 

   DATEPART(nanosecond, getdate() ) AS Nanosecond


Year Quarter Week dayofYear Month Date Hour Minute Second Millsecond

2022 4 51 346 12 12 12 15 2 677

How to Pass Command Line Arguments using Visual Studio ?

https://dailydotnettips.com/how-to-pass-command-line-arguments-using-visual-studio/

 

You are writing one application in Visual Studio which accepts some command line parameter to do some operation. You pass command-line arguments to the program when it’s been invoked from the command line. But how did you do it from Visual Studio?  You want to test your application, and do you really want to open the command prompt every time to pass the command line values. Really not. Here is a quick tip for all of you.

   Visual Studio enables nice features where you can do this on the Debug tab. Here are the steps to achieve this

1. Right Click on Project from Solution Explorer and Select Properties.

2. In the Project Properties Windows, Navigate to “Debug Tab”

3. You will find the text box “Command Line”

Well, here you can type the command line separated by Space.

image

Just write a simple console application to print the command line argument, and put a breakpoint to check the arguments,

image

So, each value separated by space has taken has a command-line argument. This will produce below output.

image

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

 https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

The Cors Error

Fix one: install the Allow-Control-Allow-Origin plugin

But the plugin fix is deceiving

Why was the CORS error there in the first place?

How does the same-origin policy work under the hood?

Origin: http://localhost:3000
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Origin: *

Did the plugin “fix” it?

Fix two: send your request to a proxy

Fix three: build your own proxy

If you want to see this in action, head to the source code for the above, along with relevant steps in the README: https://github.com/15Dkatz/beat-cors-server

Conclusion

Connect with David