SELECT record by nvarchar with LIKE when the criteria contains multiple...
I need to write a select query by nvarchar. For instance the query so far looks like this:SELECT * FROM Reservations.BlockResource WHERE Reason LIKE '%'+ @Reason+ '%'However the problem is that the...
View ArticleHow to merge multiple columns
I'm currently working on building a database in SQL Server 2008R2 to hold UPC-A codes. The UPC codes are currently split into three different columns, the first one has the first six digits followed...
View ArticleGetting Wrong values when updating the column based on Date Difference value...
Getting Wrong values when updating the column based on Date Difference value is zero.I am getting * value in the check number column. UPDATE #temp2 SET CheckNumber = UC.CheckNumber FROM #temp2 T2 inner...
View ArticleIs this Possible?
I want to pass a table varible to a linked server to cut down on the I/O:SELECT *FROMOPENQUERY(ORDERSVR,'Select * FROM...
View Articleinfo
I'm trying to understand below sql statement .can someone please tell me what does this mean :ISNUMERIC(@P1)+PATINDEX('[0]%', @P1)= 2FIRST part means - allowedVALUESFOR @p1 ARE numbers but what does...
View ArticleGroup by, how to get individual data without grouping on it?
I have joined the job history tables creating a table with server_name varchar(25), job_name varchar(25) , time_of_execution datetime , duration int. There are about 20 servers and each server can...
View ArticleSend email when certain Data is being inserted or changed in MS SQL Server table
I would like to know if possible and how I would achieve the following, whenever a new row is inserted into the following table (Contact) and the Confidential_flag Column has “Y” an email is generated...
View ArticleQuery Question
Hello All,DECLARE @TEMP TABLE ( Calls INT, DT DATE ) INSERT INTO @TEMP VALUES ( 10, '2013-05-18' ) INSERT INTO @TEMP VALUES ( 5, '2013-05-28' ) INSERT INTO @TEMP VALUES ( 5, '2013-06-15' ) SELECT...
View ArticleStrictly Academic: How do I best explain in mathematical terms what this does?
Techies--I want to be able to express how I've matched data from 2 separate tables; reporting on the action in a single line in mathematical terms-- its been 20+ years since I've been in a formal...
View ArticleDealing with Auditing data - is there a cleaner way?
Hello all,I'm working on a report to make sense of an audit trail. The audit trail is implemented is two tables, one has a row for each 'transaction' the other has a row for each column changed in that...
View Articleeasier way to pivoting the data
Hi, I have a table with currently 23 million records and it is keep increasing. Now I have to do pivoting on prog_nam, so for n number of users are there and each uses m number of applications, now...
View ArticleCreate dynamic pivot columns using two tables in sql server
Hi,i have two tables that is table1 and table2 table1 tables, select * from table1 idt mmid col1 col2 col3 col4 col5 3 1001 null bb cc as q 3 1002 a b c vf t 3 1003 b...
View Articlecan we used CTE to execute Stored procedure & avoide use of cursor ?
Hello All,I have one table having column , which is having mandatory parameter for stored proceduresp_send_dbmail.like ProfilerName,Receiver,Body etc.Table having 10 tuple with correct and valid data.I...
View ArticleHow do I check if #tempTable exists?
Is there a way in T-SQL to check to see if a #tempTable exists? I want to write a proc the uses a temp table, but I first need to see if the table already exists. if it does I want to drop it,...
View Articlesubselect in SELECT vs. in FROM as a derived table?
I'm trying to get a better understanding of when I would put a subselect inside the SELECT clause vs. putting it in the FROM clause and making it a derived table? Any general comments on this? Thanks.
View ArticleI need help with Rank
alter proc Sp_Summary_of_Top10_Shipments_By_Quantity (@BegDate datetime,@EndDate datetime,@Product varchar(max)) as select distinct T1. C01_CMM_S , T1. c01_GROSS_DATE_T_AS_A_DATE , T1....
View ArticleGet TimeStamp of the inserted rows without using external Date/Time column?
I have a table in SQL Server 2008. There is no Date/Time column. Does SQL Server store row inserted time stamp somewhere internally? If yes, how to get this time stamp?
View ArticlePIVOT Help
I don't know why but the PIVOT function escapes my comprehension.All I am trying to convert the following :DateResponseCount2012-03Sent50 2012-03Opened36 2012-04Sent45 2012-04Opened15into the following...
View ArticleSQL table column won't update
Hello,I've faced an issue recently when working on one of the tables. I'm using SQL management studio 2008. I have a table with a "MyField" column with type Char, I was trying to update the field...
View ArticleCASE Statement in SELECT
declare @Migrationdate datetime,@MigrationIndicator int set @Migrationdate='6/13/2012' set @MigrationIndicator=0 declare @temp table (accountid int , accountdate datetime) insert into @temp...
View Article