Quantcast
Channel: Transact-SQL forum
Browsing all 23857 articles
Browse latest View live

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 Article


Stored 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 Article


How 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 Article

FULL 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 Article

How 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 Article


How 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 Article

I 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 Article

Detect 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 Article


Can 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 Article


Latest 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 Article

Update 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 Article

Error 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 Article

XML 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 Article


How 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 Article

Stored 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 Article


How 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 Article

Image may be NSFW.
Clik here to view.

Be 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 Article


Scipt 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 Article

SQL 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 Article

Aggregate (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
Browsing all 23857 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>