How to get last insertd id in SQL Server 2005? [duplicate] - sql-server

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to Get Last Created Entry's ID From Sql Database With Asp.Net
How to get last inserted id?
I am facing difficulty to get the last inserted field in
selct scope identity();
SELECT *
FROM Person
ORDER BY PersonID DESC
LIMIT 1

Related

SQL Server- Get all column names in the table [duplicate]

This question already has answers here:
How can I get column names from a table in SQL Server?
(22 answers)
Closed 6 months ago.
I have a table name as 'tblOrder', having three columns. I would like to print the column names.
I want a script that should return a result as:
OrderId Name OrderTrackingNo
SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('tblOrder')
Try this

SQL Update according to unique values [duplicate]

This question already has answers here:
How to return a incremental group number per group in SQL
(3 answers)
Closed 4 years ago.
I am busy creating a VB.Net Windows Application. I am using a microsoft sql server database with a table called skedulering. I am trying to update a column (i.e Groep) with unique values based on another column (i.e. Kode). This value takes the first three characters of the Kode value and adds a integer to it. I think what I mean is best explained with the following :
All the red bordered rows have the same Groep value. Can anyone please help me to create the sql statement?
Regards
use dense_rank() to generate a running no
UPDATE t
SET Groep = left(Kode, 3) + convert(varchar(10), rn)
FROM
(
SELECT Kode, Groep, rn = dense_rank() over (partition by left(Kode, 3) order by Kode)
FROM yourtable
) t

SQL server - Query optimization [duplicate]

This question already has answers here:
IN vs OR in the SQL WHERE clause
(8 answers)
Closed 5 years ago.
I would like to know from below queries, which one would give better performance and how?
select * from TableA where (Name = 'ABC' or Name = 'DEF' or Name = 'GHI')
or
select * from TableA where Name in ('ABC','DEF','GHI')
Internally both IN and OR operators perform the same action. More importantly you need to see if you have proper index on the Name column.You can have a non-clustered index on the Name column and have one clustered index on this table.

SQL Server Integration Services 14 - Only insert if no exists [duplicate]

This question already has an answer here:
Finding updated records in SSIS -- to hash or not to hash?
(1 answer)
Closed 5 years ago.
I've the following workflow in SSIS 14:
Each source have more than million records and I need to execute this workflow everydays at week.
My question is: How can I say to SSIS that I only want to extract only the records that not exists in Table Destination? Like a
INSERT INTO TABLEA
SELET * FROM TABLEB
EXCEPT SELECT * FROM TABLEA
Many thanks!
You can use the Lookup transformation to find out if something exists already.

What does `from master..spt_values` mean [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Why (and how) to split column using master..spt_values?
I have seen something like:
Selet ... from master..spt_values where type='P'
What does this mean?
That is the syntax for specifying a databasename, schema, and table name. You can use this syntax to specify a database different from the database you are currently connected to. In your example, master is the database name, the schema name is unspecified (so it becomes the default dbo schema) and spt_values is the table name.
For clarity, the above could also be: Select ... from master.dbo.spt_values

Resources