Increment Row Number on Group
That can be accomplished with the DENSE_RANK() function: DENSE_RANK() OVER(Order By [shade]) as t_index
That can be accomplished with the DENSE_RANK() function: DENSE_RANK() OVER(Order By [shade]) as t_index
Use the ouput clause from 2005: DECLARE @output TABLE (id int) Insert into A (fname, lname) OUTPUT inserted.ID INTO @output SELECT fname, lname FROM B select * from @output now your table variable has the identity values of all the rows you insert.
Because cursors take up memory and create locks. What you are really doing is attempting to force set-based technology into non-set based functionality. And, in all fairness, I should point out that cursors do have a use, but they are frowned upon because many folks who are not used to using set-based solutions use cursors … Read more
In Management Studio, select the database, right-click and select Tasks->Export Data. There you will see options to export to different kinds of formats including CSV, Excel, etc. You can also run your query from the Query window and save the results to CSV.
You cannot alter an index – all you can do is drop the old index (DROP INDEX (indexname) ON (tablename)) re-create the new index with the additional column in it: CREATE UNIQUE NONCLUSTERED INDEX (indexname) ON dbo.YourTableName(columns to include) The ALTER INDEX statement in SQL Server (see docs) is available to alter certain properties (storage … Read more
No – a constraint is a database object as well, and thus its name needs to be unique. Try adding e.g. the table name to your constraint, that way it’ll be unique. CREATE TABLE BankAccount ( BankAccountID INT PRIMARY KEY, EmployerCode VARCHAR(20) NOT NULL, Amount MONEY NOT NULL, CONSTRAINT FK_BankAccount_Employer FOREIGN KEY (EmployerCode) REFERENCES Employer … Read more
My guess is that you don’t really want to GROUP BY some_product. The answer to: “Is there a way to GROUP BY a column alias such as some_product in this case, or do I need to put this in a subquery and group on that?” is: You can not GROUP BY a column alias. The … Read more
@@ROWCOUNT will give the number of rows affected by the last SQL statement, it is best to capture it into a local variable following the command in question, as its value will change the next time you look at it: DECLARE @Rows int DECLARE @TestTable table (col1 int, col2 int) INSERT INTO @TestTable (col1, col2) … Read more
Not 100% sure what you mean: Trusted_Connection=True; IS using Windows credentials and is 100% equivalent to: Integrated Security=SSPI; or Integrated Security=true; If you don’t want to use integrated security / trusted connection, you need to specify user id and password explicitly in the connection string (and leave out any reference to Trusted_Connection or Integrated Security) … Read more
You can’t use aliased columns in a WHERE clause. You can try using a derived table. Perhaps something like this (sorry, not tested): SELECT * FROM ( SELECT SQRT( POWER( cast(Program_Latitude as float) – cast(‘41.5126237’ as float), 2) + POWER( cast(Program_Longitude as float) – cast(‘-81.6516411’ as float), 2) ) * 62.1371192 AS DistanceFromAddress from tblProgram … Read more