Pivot query with dynamic number of columns
Dear People,Using SQL 2012, I am trying to create a pivot query where I do not know all of the column names in advance. My understanding is the only way to do this is to generate the query dynamically...
View ArticleHow to eliminate NULL values from case statement?
I have the following query where I am trying to eliminate the NULL record. How can I do this? My query:select AttendedSchoolLast3Months = case when d.scrnval_id =...
View ArticleHow to change Owner of ReadOnly Database which is configured with logshipping
Hi All,I have primary database configured with logshipping and SA is owner of this database, I have destination database as ReadOnly (standby) copy, but somehow I think it was restored as another...
View Articleget more columns from group by
I have many queries similar to this where I am grouping account numbers and transaction ids by a max(date) or max(amount). For example, account_no = 101 with several transaction ids and a max(date). I...
View ArticleHas Output of Stored Procedure (2012) to come in a order by default? SP is...
Hi Guys,I am using SQL Server 2012. Today I noticed that Output of Stored Procedure is coming in a order by default. But when same query I run separate, output is not in order.The reason I ask this...
View ArticleHow to access sysobjects and syscolumns on a different database?
I'm attempting to write a script that iterates over all tables and their columns in all databases resident to a SQL Server connection. I can do either of these but cannot figure out how to merge the...
View ArticleT-SQL INSERT INTO; Problem with data truncation error
SQL Version: 2008 R2PROBLEM: I'm having issues with the following code involving an INSERT INTO statement. I'm getting the error "String of binary data would be truncated. The statement has been...
View ArticleSet a flag if certain columns contain a value
I have a table with multiple different columns. Each of these fields can contain 1 or 0. So how would I write a statement that sets a "flag" if each of these columns contain a 1. Again, I only want the...
View ArticleHow to load excel sheet datas to tempt table on SSMS, no export, import...
I think I can use linked server but could not get sample code.
View Articlehow do i delete records from the User defined table types?
hi friends, when I create a user defined table type with two column- id int and isBlocked Bit- to will be created in theuser-defined table types folder of the Types folder. so if I want to delete...
View ArticleTSQL Help needed using time datatype
i have a requirement to get the appropriate RunID based on the Starttime.I'm not able to get results if Starttime is beween 00:00 and 05:00 for ABC Dataset. Please...
View ArticleDocuments view permission
there is a designation table and there is admins e.g supervisor,manager ,directorso when supervisor upload document then he/she not able t see his/her documentsi try this spSELECT...
View ArticleIncluding Extra Columns in a Pivot
Dear AllWith much help from you all in the forums, I have created a pivot in order to display data in my child rows as columns. The output is exactly as I had hoped except for there is an additional...
View ArticleWriting a text to a text file
I need to write a text into a text file.I have a table like as follows:ID Name1 ABC2 XYZAnd i need the about as follows:In a text file it needs to show as: For Example it needs to...
View Articleconvert to column records to column header
Dear All, I have a query, where i have a table where two columns is there.I want to write a query convert first column records in Column header and second column records would come under that...
View ArticleSplit date range without Calendar table
Hi guys!Is there any way to split date ranges (to days / hours / minutes) in one table without using Calendar table (without joining 2 tables)?Reason I'm asking this is because we have a huge Fact...
View ArticleNot all threads are used in Parallel execution plan
Hi experts!I wrote a query which cross joins 2 tables:select T.PeriodStart, T.PeriodEnd, count(SessionID) as count_SessionID,sum(cast(SessionDuration as bigint)) as Sum_SessionDuration from #t T cross...
View ArticleQuery Needed
Table1 Table2 productCode batchNo batchNo availableQty BURSLO BS20GO-2001 BS20GO-2001 50 BURSLO BS20GO-2011...
View ArticleSQL Extract Variable String in Variable Position with Variable length from...
i want to extract a variable string from an ntext field. Sample Data in Background_text (ntext) function changeFocus() { document.getElementById('skipContent').style.visibility = 'visible';...
View Articlet-sql 2008 r2 parameter values
In t-sql 2008 r2 I would like to know how to set a variable value that would be similar todeclare @avar varchar(3)set @avar in ('ABS', YUR', 'UNV', 'MED')The @avar character can be one or all of the...
View Article