Tuesday, April 23, 2013

[T-SQL] Merge Statement over a linked server

[T-SQL] Merge Statement over a linked server


Merge Statement over a linked server

Posted: 24 Nov 2012 07:42 AM PST

Does anyone know a way of running a MERGE statement across 2 tables over a linked server?Getting the message "The target of a MERGE statement cannot be a remote table, a remote view, or a view over remote tables."

Select statement using a max

Posted: 23 Apr 2013 01:04 AM PDT

Hi i hope someone can help mw out I have the following selct statement that is working fine Select Substring(Name,9,10) 'Desk' ,Convert(Int,BchCode) As 'bchCode' ,CallDate ,Max(CallTime) 'LastCall' ,Min(CallTime) 'FirstCall' ,Count(SummaryFlag) 'Outbound Attempts' from tbl_OutboundCallDataWhere CallDate between @startdate and @enddate And SummaryFlag In ('W') Group By bchCode,CallDate,NameI have been asked to add in the duration off the Last call (exists in tbl_OutboundCallData and call CallDuration) and im struggling if i just add in the duration then i have to add is into the group by element and this is returning all the records of duration and not just the one related to the Last CallHope that makes senseany help would be gratefully appreciated as im going mad trying to get this orted Thanks

UPDATE statement help

Posted: 23 Apr 2013 12:43 AM PDT

Morning guys,I need a lil help with an update query...I have a working table that has all these columns in it...two of the columns are CustomerID and IDAlias...When importing into the table it loads everything except the IDAlias column...I have this other working table that has CustomerID and IDAlias in it...This is where the alias' are populated...The thing is: I need to populate the first working table with the alias' for each CustomerID using the other working table that has the alias for each customerID...The statement that I have been doing :UPDATE TableASET IDAlias = (SELECT Alias FROM TableB INNER JOIN TableA ON CustomerID = CustomerID)I keep getting subquery returned more than 1 value and I understand that error...Im just confused on how to populate that alias field...

Difference between cursor and While loop

Posted: 22 Apr 2013 03:44 PM PDT

Hi all, Can any one explain me What is the difference between Cursor and While Loop? I have read about two concepts but end up with confusion..Which one gives better performance??

Order By in Sql Server

Posted: 22 Apr 2013 08:56 PM PDT

Hi All,In a table i want to apply order by. My database is 20-20 and table is errorreport where I have only 4 columns (rpt_id, error_id, file_id, errorlino). I have written the below query and it is working fineselect * from errorreportwhere file_id=605 order by error_id descthe result is like belowrpt_id error_id file_id errorlino46 95 605 147 46 605 248 41 605 349 30 605 4But I don't want this. I want the list like belowrpt_id error_id file_id errorlino46 [b] 95[/b] 605 147 [b]30 [/b] 605 248 [b]41[/b] 605 349 [b]46 [/b] 605 4I want to set the asc or desc order. Is it possible to do in SQL?Please help!

Distinct Query Help

Posted: 22 Apr 2013 11:41 AM PDT

I HAVE DATA LIKE THIS ID DATE PID 691935 2012-05-11 15:32:09.377 00071015523691935 2012-05-11 00:00:00.000 00093063801691935 2012-05-11 15:34:37.147 00093103993691935 2012-09-19 11:27:55.420 00093715310691935 2012-11-16 15:28:21.843 00093715410691935 2013-03-08 15:19:53.013 00093720210691935 2013-03-08 15:19:22.867 00093721401691935 2012-07-13 00:00:00.000 00247035330691935 2012-07-13 15:53:21.343 00247035430691935 2013-03-14 13:50:01.803 00247181304691935 2013-03-14 00:00:00.000 00247196500691935 2012-10-12 00:00:00.000 00456132100691935 2012-05-11 15:32:36.580 51079099720691935 2012-05-11 15:31:38.957 53489046910691935 2012-10-12 13:51:39.530 63739013701 HOW I CAN use this logic here in the above dataI ID,PID of MAX(DATE) The end result should beID DATE PID691935 2013-03-14 13:50:01.803 00247181304 Here is my codeSelct DISTINCTID,MAX(DATE) MAX_DATE,PIDFROM MytableGroup by ID,PID I am not getting what I want. Any help would be great appreciate.

T-SQL Rename Multiple Tables

Posted: 22 Apr 2013 01:09 PM PDT

I am looking to rename a lot of tables using a wildcard,for example, the table names are:OrderItemOrderItemsOrderItemssI would like them to be renamed to:OrderItem2OrderItems2OrderItemss2Can this be done using a wildcard so I don't have to specify the full table name? Thanks.

Interview Questions

Posted: 22 Apr 2013 02:54 AM PDT

Hi I am facing following interview questions. table i am having one column .That column records like following SATHEESHKUMARARUN[b]rahul[/b][b]s[/b]URYAS[b]elvi[/b]Now i want following results.whever i am using lower case letter.please help merahulsURYASelvi

No comments:

Post a Comment

Search This Blog