I am using SQL Server 2008/2012.In my database I have a table which has encrypted column. The column is encrypted by using following query – Create the example table CREATE TABLE [HR].[Employees]( …
Tag: tsql
How to fold table rows with duplicated ID’s in T-SQL
I’ve googled for a while but haven’t found an aswer so I request your help. I have a subquery which returns me these values: And I need to make it look like this: Answer
how to select multiple rows using where (two conditions) in sql?
When the condition is based on one column, I can use either IN, AND, or OR, but if the condition is based on two columns, how to write the query? For example, I need to set up the value of column 1 to NULL in the following rows: column 2 = ‘red’ AND column 3 =’ Monday’, column 2 =
add bool column within existing table
I am trying to dd a column, to a database with the program Microsoft SQL Server Management Studio. I already have a database, with a table, in that table i need to add another column.. but it keeps saying it cannot find type bool or boolean. my code : Any ideas ? side question, any idea how to alter an
SQL Server 2012 takes long time on simple alter to add NULL columns
I have a problem to alter table in SQL Server 2012, it takes a long time to add 04 columns being allowed NULL to large table with 340 columns and approximately 166M rows and 01 non-clustered index This problem happens only specific table after restoring. I’m waiting the execution for 10 hours but it’s not finished so I must cancel
SQL – Remove all HTML tags in a string
In my dataset, I have a field which stores text marked up with HTML. The general format is as follows: <html><head></head><body><p>My text.</p></body></html> I could attempt to solve the problem by doing the following: However, this is not a strict rule as some of entries break W3C Standards and do not include <head> tags for example. Even worse, there could be
How to use order by on a calculated field in SQL?
How to use order by on a calculated field in SQL? This is giving me ‘Total1’ column does not exist but as you see I have created it and is working if I am not using the order by clause. Answer You can do what Mureinik suggests and use the ordinal notation of ORDER BY 13, which means “order by
Select all rows and ignore the first row
I’m currently using the following SQL query which is returning 25 rows. How can I modify it to ignore the first row: I’m using SQL Server 2008. Thanks. Answer You can use EXCEPT in SQL Server 2008. For SQL Server 2012 and above, you can use FETCH OFFSET
LAG functions and NULLS
How can I tell the LAG function to get the last “not null” value? For example, see my table bellow where I have a few NULL values on column B and C. I’d like to fill the nulls with the last non-null value. I tried to do that by using the LAG function, like so: but that doesn’t quite work
Invalid Column Name using Dynamic SQL
I am attempting to use Dynamic SQL for the 1st time – Now i understand the gist of it to an extent however attempting to enter a parameter into a temp table using Dynamic SQL i am getting the “Invalid Column name” when i am simply try to enter this as text not intending to be a column. On a