Need help with the TSQL.
I have 2 tables and need to check if the record exist in the #diagnose table and meet the rules below than return it. I have the query below but need your help to get the desired output below. SQL 2008...
View ArticleSimplifying WHERE column1=value1 AND column1= value2 filter
Hello,I am trying to build a query that compares all values for a given column in "AND" operation.DECLARE @param NVARCHAR(100 SET @param = '1,2,3,4,5'SELECT * From CompanyWHERE ID = 1 AND ID = 2 AND ID...
View ArticleInteger/Numeric value assigned to Datetime type variable
A variable declared of DateTime type accepts Integer and NUmeric values , where as rest data types in the same group (DATE,TIME,DATETIME2) doesn't accept.If an integer value is assigned , SQL server...
View ArticleGeneral t-sql script
I have the following parameters and requirements and I have to write sql script, having issues doing it.I need assistance as I am new to t-sqlWe need to create a generic sql script that will accept the...
View ArticleQUERY OPTMIZATION
We have inluded follwoing query in our SSIS packages. Select * from commit where (unit='BBMIN' or unit='BLG' or unit='GEm' or unit='OKGM' or unit='OKGV' or unit='SWLP' or unit='TUC' or unit='TXU')the...
View ArticleHow to audit access to all objects in a database?
I want an audit file row each time an object is accessed in a database. I have this code running in SQL2008R2. I am testing in a database called SQLAudit.USE [master] GO CREATE SERVER AUDIT...
View ArticleNeed to get values from that year
Hi All, I am having the table which is having columns as last reported quarters from 2010 to 2014and i need to add which four quarters belongs to same year pls any one help me ASAPKindest Regards,S...
View ArticleSQL-Update using above rows
/*Hi Experts I am working on SQL 2012 , I have a table example "TEMP1" where Record of single Person comes multiple Time ,Based on there SourceID. I need to Insert This Data into another Table...
View ArticleIs there a better way to write this SQL? - I wish to use something other than...
Is there a better way to write this SQL?SET @IMP_COUNT = (SELECT COUNT(*) FROM LinkedServerName.DatabaseName.dbo.TableName WHERE 'P-' + CASE WHEN CaseNoExt is null THEN CaseNumber...
View ArticleTsql query for Pivot table help
Hi I got a table like belowI want to group by T-Date and find the count of Transmitter if its "ABC" and next column must have the count of Receiver if its "ABC". create TABLE Transition (T_Date...
View ArticleAssign conditional allocation value within Select query
I have two tables viz. #Exported_Data and User_Details.#Exported_Data: (User_Id, User_Name, Status, Office_Id, Dept_Id, Service_Id, Allocation)User_Details: (User_Id, Office_ID, Dept_Id, Service_Id,...
View ArticleDETECT CHANGE IN ROWS FROM TWO TABLE having Same Columns USING T-SQL
HiHow to DETECT CHANGE IN ROWS FROM TWO TABLE having Same Columns USING T-SQL I have Source Data which comes from Veeva.We take Source data and Update it using MDM process. ( only few records will be...
View ArticleHow to find TopLevel Company in a table
CREATE TABLE #Organizations (ID INT, Number INT, Name varchar(30), SuperiorOrganizationID INT) INSERT INTO #Organizations VALUES (1, 1, 'Dell', NULL), (2, 2, 'HP', NULL), (3, 100, 'IBM World', NULL),...
View ArticleBcp export with columns name
Hi, I'm using BCP utility to export data from MS sql server 2012. I need to have on top of the data file the names of only the columns that I export.I know that I can export the names of the columns...
View ArticleMatch *any* three columns
Hi All,I'm looking for ideas on how to approach this. Scenario:Table1: FName, LName, DOB, City, Zip, ...more columns Table2: FName, LName, DOB, City, Zip, ...more columns-some different than Table1I...
View ArticleTSQL 2008 R2- To condense the table by forming groups without Cursor logic
Hello,I have the following tableSHIFTINDEX EQMT OPERATOR STARTTIME ENDTIME 100 418 UNKNOWN 0 1400 100 418 LUKE...
View ArticleHow to split one column into several columns by the character ";"
How to split one column into several columns by the character ";" ?Thanks.
View ArticleNested Recursive Query
I have a recursive query that gets me half way to where I need to be. The only way I can see to get the result I need is to run that query recursively.Is there a way to do this and then dump the...
View ArticleWill we ever be able to directly ORDER BY @SortExpression ?
Without seeking promises or guarantees, what are the chances of being able to use a parameter directly in ORDER BY in some future version of SQL Server?Is it impossible due to the architecture of SQL...
View ArticleConversion failed when converting date and/or time from character string in...
Hi,I created LinkedServer in SSMS from MYSQL DB.When i Execute below open Query its working FineSELECT * FROM OPENQUERY(MySQL,'call GASP_sales_aps(''2013-04-01 00:00:00'',''2013-05-01 23:23:59'')')But...
View Article