Tuesday, 19 April 2022

How to transpose data in MSSQL

 

Declare @UserID nvarchar(256)

Declare       @MsgType int

 

set @UserID = userID

set @MsgType = 3

 

CREATE TABLE #tmpBus3

(

   AdminUnitID int,

   AdminUnitName nvarchar(256),

   CategoryName nvarchar(256),

   CategoryID int,

   CategoryLevelID int,

   ParentID int,

   IsMainAdminUnit bit,

   PersonID int,

   Name nvarchar(256),

   UserID nvarchar(256),

   level int,

   LevelName nvarchar(256)

)

       INSERT INTO #tmpBus3

       Exec [Archv].Cust_GetContactsbyUserID @UserID,@MsgType;

 

       DECLARE @tmpTable3 AS nvarchar(max);

       SELECT @tmpTable3 = CONCAT(COALESCE(@tmpTable3 + ']  nvarchar(255), [','['),CONCAT('Col', ROW_NUMBER() OVER(ORDER BY LevelName ASC)))

         from #tmpBus3

         set @tmpTable3='CREATE TABLE #tmpTable3 ( '+@tmpTable3+']  nvarchar(255) )'

           DECLARE @levels AS nvarchar(max);

SELECT @levels = CONCAT(COALESCE(+@levels + ''',N''',''), AdminUnitName)

  from #tmpBus3

  set @levels=''''+@levels+''''

 

         DECLARE @SqlStatement1 NVARCHAR(MAX)

         SET @SqlStatement1 = N''+@tmpTable3+' insert into #tmpTable3 values ('+@levels+') select * from #tmpTable3';     

         print @SqlStatement1

          EXEC(@SqlStatement1)

Drop Table #tmpBus3

The result will be as in the following screenshot




Tuesday, 22 March 2022

Enable geoserver to serve frond end and overcome the CORS problem

 Go to geoserver\lib in the lib directory of geoserve to find jetty-servlets-XX.jar and jetty-util-xx.jar (xx means different versions) two jar packages


Copy the all jars packagesfrom geoserver\lib to the geoserver\webapps\geoserver\WEB-INF\lib\ directory

 Go to the geoserver\webapps\geoserver\WEB-INF directory to find web.xml and add the following XML:


<context-param>

    <param-name>ENABLE_JSONP</param-name>

    <param-value>true</param-value>

</context-param>

<filter>

      <filter-name>cross-origin</filter-name>

      <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>

  </filter>

   <filter-mapping>

        <filter-name>cross-origin</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>



add the following line at the beginning of startup file of geoserver   

"C:\Program Files\GeoServer\bin\startup.bat" edit it by notepad++

set geoserver.xframe.shouldSetPolicy=false


or using the service 

open the wrapper folder C:\Program Files\GeoServer\wrapper

and edit the cmd command which placed at the end of the jsl64 file

-Dgeoserver.xframe.shouldSetPolicy=false



stop the service and run the startup.bat as administrator

Everything will be OK


Thursday, 3 February 2022

DNN delete all duplicated users

declare @email as nvarchar(256)

 

DECLARE db_cursor CURSOR FOR

SELECT [Email]

  FROM [Users]

  group by [Email] 

  having count([Email])>1

 

OPEN db_cursor 

FETCH NEXT FROM db_cursor INTO @email 

 

WHILE @@FETCH_STATUS = 0 

BEGIN 

    

         UPDATE dbo.UserPortals

                           SET

                                  IsDeleted = 1

                           WHERE  PortalId = 0

                           and UserId in (

SELECT [UserID]

  FROM [Users]

  where Email =@email and ([UserID] not in (SELECT [UserID]

  FROM [RelatedTable1]

  where [UserID] in(SELECT [UserID]

  FROM [Users]

  where Email =@email)

  UNION

  SELECT [UserID]

  FROM [RelatedTable2]

  where [UserID] in(SELECT [UserID]

  FROM [Users]

  where Email =@email))))

      FETCH NEXT FROM db_cursor INTO @email

END

 

CLOSE db_cursor 

DEALLOCATE db_cursor


Wednesday, 12 January 2022

globals.navigateurl is obsolete

 

DotNetNuke.Common.Globals.NavigateURL() in Dnn 8, but in DNN 9 use the following 


  • PortalSettings.ActiveTab.FullUrl to replace NavigateURL()
  • Response.Redirect(EditURL()) to replace NavigateURL() with parameters

Saturday, 11 September 2021

Loop through table in mssql

SET NOCOUNT ON

 

DECLARE @ParcelCode nvarchar(100)

 

DECLARE load_cursor CURSOR FOR

    SELECT [ParcelCode]

    FROM dbo.[Info_parcels05]

 

OPEN load_cursor

FETCH NEXT FROM load_cursor INTO @ParcelCode

 

WHILE @@FETCH_STATUS = 0

BEGIN

    BEGIN

              update [dbo].[Info_parcels05]

                           set PriceByHumen=(SELECT FLOOR(RAND()*(1000000))),PriceByMachine=(SELECT FLOOR(RAND()*(1000000)))

                           where ParcelCode=@ParcelCode

         

    END 

    FETCH NEXT FROM load_cursor INTO @ParcelCode

       print @ParcelCode

END

 

CLOSE load_cursor

DEALLOCATE load_cursor

GO