Skip to main content

How to duplicate the last record through SQL query

Dear Readers,
Today i share a code which may be help you out once in a blue, last few days back i found i request from my customer about duplicating the record in to new case for saving the time.

I have done this through query and i want to share this with you, I hope it will save your time.


INSERT INTO Table_Name
( field1, field2, field3,...)
SELECT top(1) field1, filed2, filed3, ...  FROM Table_Name  WHERE primaryKey = yourvariable

Make sure do not include the primary key + autonumber field in this query.

Also you need to make sure the sequence of the inserting field (field1, field2, field3...) will be in same sql field sequence


If you want to add any variable in the field here is the sample query
Declare @var1 int
Declare @var2 int
Set @var1 = 1
Set @var2 = 2
insert into Table_Name(field1, field2, field3,...)
select * Column_Name, @var1, @var2  from second_table where condition

I hope it save your time

Regards
Rashid Imran Bilgrami
http://www.bestvisualization.com



Comments

Popular posts from this blog

How to convert and crack windows server 2012 from Evaluation to Full

Dear All This is a way how you Convert Evalution to Full Step1: Open CMD and run following command DISM /online /Get-CurrentEdition <edition ID> is like ServerStandard with out Eval Step 2: DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula WINDOWS SERVER 2012 Serial Key Windows Server 2012 DataCenter: 48HP8-DN98B-MYWDG-T2DCC-8W83P Datacenter: Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW Standard: XC9B7-NBPP2-83J2H-RHMBY-92BT4 Standard R2: DBGBW-NPF86-BJVTX-K3WKJ-MTB6V Server Essentials: K2XGM-NMBT3-2R6Q8-WF2FK-P36R2 For Standard R2 here is a command For R2 its like that DISM /online /Set-Edition:ServerStandard /ProductKey:DBGBW-NPF86-BJVTX-K3WKJ-MTB6V /AcceptEula Regards

DNN 7 Won't go into edit mode or not working with control bar

Dear All, Today when i install the DNN 7 then i found and issue in edit mode after installation. The problem is when i go to edit mode the page refresh with out enabling the edit mode, after a short research on Google i found the solution. I hppe it save your time 1. backup your web.config 2. Open your web.config in a text editor 3. within the web.config file, find the <system.webserver><modules> section. 4.  If the <modules> section says <modules runAllManagedModulesForAllRequests="false"> change it to <modules runAllManagedModulesForAllRequests="true"> OR  if it just says <modules>, change it to <modules runAllManagedModulesForAllRequests="true"> 5. Save the config file. 6. Retry by refreshing the page and trying again.  You can also test this out by trying to a do a journal post (which also uses the services framework in an authenticated way. If some how its will not work then, you must chang...

Take Back up for all SSRS Report

 Dear All,  If you want to take a backup of the complete SSRS report server, please follow the below setups  Run PowerShell with Full Administrator Rights # ------------------------------------------------------ #Prerequisites Install - Module - Name ReportingServicesTools # ------------------------------------------------------ #Lets get security on all folders in a single instance # ------------------------------------------------------ # Declare SSRS URI $sourceRsUri = 'http://ReportServerURL/ReportServer/ReportService2010.asmx?wsdl' # in my case http:// sjerpsrvr2/ReportServer/ReportService2010.asmx?wsdl # Declare Proxy so we dont need to connect with every command $proxy = New - RsWebServiceProxy - ReportServerUri $sourceRsUri #Output ALL Catalog items to file system Out - RsFolderContent - Proxy $proxy - RsFolder / - Destination 'C:\SSRS_Out' - Recurse I hope it will work Regards Rashid Imran Bilgrami 3ART Technologies https://www.3art.t...