Better and efficient way to write this query
Hello All,I am asking whether there is a better way to write below query or not.Or could you give me some advices make it perform well ?select id_emp,amount from ( select...
View ArticleStored Procedure Best practice for INSERT, UPDATE, DELETE and INSERT
Hi,I have a simple form which involves INSERT, UPDATE, SELECT and DELETE functions. I want to write these queries in stored procedure.I want to know which is the best practice from the following.1....
View ArticleHow to set FK between 2 tables?
I have two tables in SQL Server 2012. I need to help with SQL query and also how should I model with UML ER diagram.Requirements: A) CustomerCode is primary key in Customer table. For example...
View ArticleFULL OUTER Join Problem
Hello EveryoneI have a problem when I execute the query below then it displays which entry is within typed date parameters. For example, I type date parameters to display projects between 01/01/2012...
View ArticleHow to do this select?
I have a table with one of the columnw being LabOrg.I want to pull back 1000 records (or all if less than 1000) for each distinct laborg in the table all at once.So if tableA looks like this:LabOrg...
View ArticleHow to get the rowcount for rows inserted and updated in merge procedure
Hi All, I have a stored procedure which is below :- if we see in the end , I am setting the rows inserted = row count which gives me the row count for any rows inserted and as this being a merge...
View ArticleI want to replace the the column value with other
Hello This is three table query. Following is structure of the tables ClassClassification table USE [] GO /****** Object: Table [dbo].[ClassClassification] Script Date: 12/03/2013 12:02:07 ******/ SET...
View ArticleDetect if data retrieved in View
Lets say I have this View on MyTable: CREATE VIEW MyView (IDValue, LastName, FirstName) AS SELECT IDValue, LastName, FirstName FROM MyTable;Is there a way in the View that I can tell that...
View ArticleCan I use IN as part of a case statement?
Can I use an IN statement as part of a case, something like thisSELECT COLB, CASE WHEN mt.testshoe IN (34,55,88) OR o.TestType IN (201) THEN 'ABC'WHEN (ColA IS NULL) THEN 'DEF' END AS testval
View ArticleLatest Date Query Issue
Hi:I have three tables:Core_Table holds DeviceNo and location codes. The PK is DeviceNo.DeviceNo Location Code DeviceType12345 A 2 45678...
View ArticleUpdate query
Hi,I have temporary table with records mem_id and recpt_id. I want to update the same table with advance money based on a calculation.I have more than 40,000 records. How can write a query to loop in...
View ArticleError while running a cursor which gets date from a table
Hi, I have a cursor inside a stored procedure which basically gets the date from a table and runs the query for that dates and inserts into another table.Below is my procedure ALTER procedure...
View ArticleXML Extract
DECLARE @xmlDoc XML; DECLARE @handle INT; DECLARE @Xml XML = N'<propertyList date="2013-05-21-09:13:38"><residential modTime="2013-05-21-09:13:39" status="sold">...
View ArticleHow to convert days into number.
If the user want to archive data older than 30 than @numberofDay should convert into date like 11/03/2013. They want to pass in days as int and the process should convert that into day.Any help would...
View ArticleStored Procedure code, How to search for tables
Hi folksI had a question which I'm not sure whether its possible or not:I have a table in my "SQL Server 2008" database. I need to find out, in which procedures or functions it’s being used. Is there a...
View ArticleHow to convert days into number.
If the user want to archive data older than 30 than @numberofDay should convert into date like 11/03/2013. They want to pass in days as int and the process should convert that into day.Any help would...
View ArticleBe our December TechNet T-SQL Guru. Give the gift of code!
It's that time of the year again!It's Giving time!A time to think of those less awesome than you.A time to give something back to the community.Think of those happy faces you will make, as they open...
View ArticleScipt does not run in 2008 but runs in 2000 server! Can any one help!!!!
INSERT INTO Appraisers (ContactID, FirstName, LastName, Company, PostDate) SELECT TopAppraiserList.[Appraiser Id], TopAppraiserList.[Appraiser_First Name], TopAppraiserList.[Appraiser_LAST...
View ArticleSQL Query To Check not null and update to some value
We have a table and when I run a select statement I want to set value = yes if EmpID is Not NullSelect Number, EmpID from Table1Table1 Number EmpID 7812262261 NULL 07875 116189 NULL 7956436533 NULL...
View ArticleAggregate (MAX) Value in Returned Result Set
I am using SQL Server 2012 and have a simple query. I need to get the maximum qty for each sales rep and display that quantity along with the order number and the sales rep number in my result...
View Article