I have to add a few columns to a table and I also need to add these columns to all the views that use this table. Is it possible to get a list of all the views in a database that use a certain table? Answer This should do it:
Tag: sql-server
Getting max value from rows and joining to another table
Sorry if this is being stupid, I am really a newbie trying to nail this. Table A: ID Rank Name 1 100 Name1 1 45 Name2 2 60 Name3 2 42 Name4 2 88 Name5 Table B: ID FileName 1 fn1 …
Selecting most recent and specific version in each group of records, for multiple groups
The problem: I have a table that records data rows in foo. Each time the row is updated, a new row is inserted along with a revision number. The table looks like: id rev field 1 1 test1 2 1 …
SQL – Subtracting a depleting value from rows
I have a situation where I need to take a “quantity consumed” from one table, and apply it against a second table that has 1 or more rows that are “pooled lots” of quantities. I’m not sure how to describe it better, here’s what I mean from a table perspective: I need a resulting rowset from a SQL query that
NVARCHAR(?) for Email addresses in SQL Server
For Email addresses, how much space should I give the columns in SQL Server. I found this definition on Wikipedia: http://en.wikipedia.org/wiki/Email_address The format of email addresses is local-part@domain where the local-part may be up to 64 characters long and the domain name may have a maximum of 253 characters – but the maximum 256 characters length of a forward or
How can I perform a SQL ‘NOT IN’ query faster?
I have a table (EMAIL) of email addresses: EmailAddress ———— jack@aol.com jill@aol.com tom@aol.com bill@aol.lcom and a table (BLACKLIST) of blacklisted email addresses: EmailAddress ——–…
How to count number of records per day?
I have a table in a with the following structure: I would like to know how I can count the number of records per day, for the last 7 days in SQL and then return this as an integer. At present I have the following SQL query written: However this only returns all entries for the past 7 days. How
Simple update query is taking too long
I have a table CurrentStatus in my database (subscription database in a merge replication) Columns are StatusID {Primary Key + Clustered Index}, StatusName, StatusDate, UserID,CreatedDate, …
How to select info from row above?
I want to add a column to my table that is like the following: This is just an example of how the table is structured, the real table is more than 10.000 rows. So for every time there is a value in ‘Subgroup’ I want the (New_Column) to get the value [No_] from the row above There are cases where
A way to extract from a DateTime value data without seconds
I have an sql DateTime (ms sql server) and want to extract the same date without the seconds: e.g. 2011-11-22 12:14:58.000 to become: 2011-11-22 12:14:00.000 How can I do this? I was thinking to use DATEADD in combination with DATEPART but seems very error prone (besides performance issues) Answer For a solution that truncates using strings try this: CHAR(16) works