MSSQL how to update a column base on a row number
Tech-Today

MSSQL how to update a column base on a row number


Just recently I was asked to normalized or divide a table into 2 tables. Unfortunately, the only column that linked them (email) allows multiple same values, even aggregate would not do (email, password, etc). This is because there's a field that marks a user as inactive. So a single email can have many inactive records.

So linking the 2 tables, I only have 1 choice to update the other table based on row number, since the first table is filled with auto number.

How did I update a column base on a row number? See:

UPDATE Users
SET MainTableId=t.Seq
FROM (SELECT id, Row_Number() OVER (ORDER BY id) as Seq FROM Users) t
INNER JOIN Users ON t.id=Users.id

--test the table if properly updated
select * from Users




- Insert An Md5 Password In Mssql
To md5 a string in mssql we execute this query: select HASHBYTES('MD5', 'password') //But this has a problem because it returns a VarBinary data type which is a garbled text. So it should be converted first to NVarchar: SELECT CONVERT(NVARCHAR(32),HashBytes('MD5',...

- Magento Email To A Friend Not Working, Even After Updating Product_share.html
After we have successfuly setup our magento store, we've been testing its functionality and found out that email to a friend is not working properly. The product link and image are missing. What we did: 1.) After checking the controller for sendfriend,...

- Operation Must Use An Updateable Query
I am currently developing a certain application in MS Access and I need to link 2 databases, select data from one and move it to the second. In access I have no problem using the TransferDatabase command. DoCmd.TransferDatabase acLink, "Microsoft Access",...

- Change The Datagrid Column Header Text / Title
Using .Net1.1, I experienced a problem on how I could change the header text of a datagrid. Normally, you can set it like this (using the DataGridTableStyle): DataSet ds = query("Select field_name from table"); datagrid.DataSource = ds.Tables[0]; //and...

- How To Add A Customize Product Admin Fields In Zencart By Editing/adding Extra Codes
Problem: How to add a product custom field named length. This to consider (modifications in): 1.) database 2.) scripts ----------------------------------- 1.) Database - a custom column should be add to the products table. Execute this line (for column...



Tech-Today








.