Wednesday, November 14, 2018

Convert Rows in to Columns in SQL

I am facing an issue in which I need to convert Rows in to Column in SQL.

SELECT id,
       video_data1,
       video_data2,
       video_data3
FROM   (  SELECT   (tv.id),
                    Cast(english_value AS  NVARCHAR(max)) AS 'English_value', tv.NAME AS 'Category_Name',
                    'Video_Data' + cast(row_number() OVER(partition BY tv.id ORDER BY tv.id) AS varchar(10))   columnsequence
                FROM     tv ) temp PIVOT ( max(english_value) FOR columnsequence IN (video_data1,
                                                                                     video_data2,
                                                                                     video_data3) ) piv

As you can see I am using Cast(english_value AS  NVARCHAR(max)), it due to I cannot use ntext in max so I need to change
data type .

After using Pivot: 


Refer Link:
https://www.youtube.com/watch?v=C0mQqDnF7wQ



Thursday, November 8, 2018

Multiple Language Caching in Asp.net

Recently I am facing an issue in which when ever user open a website some of the static control like slider hit our database. So what I have to do I need to prevent that hit and get data from Cache.
One more thing is that we support multiple language in our website its means when user login as English user he get data in English and when Chinese he will get Chinese and so on , So I need implement multiple language caching.

time define in web.config file
   Dim CacheTime As String = ConfigurationManager.AppSettings("CacheTime")

languageId in which i get language of user
 
If Cache("HomePage" & languageId.ToString()) IsNot Nothing Then
            ds = DirectCast(Cache("HomePage" & languageId.ToString()), DataSet)
        Else
            ds = GetHomePageContent(Me.languageId)
            Cache.Insert("HomePage" & languageId.ToString(), ds, Nothing, DateTime.Now.AddSeconds(Convert.ToInt32(CacheTime)), System.Web.Caching.Cache.NoSlidingExpiration)
        End If