I want to write a sql statement to trim a string ‘Hello’ from the string “Hello World’. Please suggest. Answer
Tag: sql-server
How to select only the first rows for each unique value of a column?
Let’s say I have a table of customer addresses: In the table, one customer like John Smith can have multiple addresses. I need the SELECT query for this table to return only first row found where there are duplicates in ‘CName’. For this table it should return all rows except the 3rd (or 1st – any of those two addresses
MS SQL query to list count by status
I want to achieved the result below. I want to list all records having a status of “For Approval” together with this condition: For example for Username ‘Leo’ Then sum all the status having “For Approval” which is the checker is ‘Leo’ with the condition above Answer I think this is what you are after; if its not i have
T-SQL Conditional WHERE Clause
Found a couple of similar questions here on this, but couldn’t figure out how to apply to my scenario. My function has a parameter called @IncludeBelow. Values are 0 or 1 (BIT). I have this query: If @IncludeBelow is 0, i need the query to be this: If @IncludeBelow is 1, that last line needs to be excluded. (i.e don’t
How to retrieve records for last 30 minutes in MS SQL?
I want to retrieve records for last 30 minutes in a table. How to do that? Below is my query.. select * from [Janus999DB].[dbo].[tblCustomerPlay] where DatePlayed < CURRENT_TIMESTAMP and …
Why doesn’t SQL Server support unsigned datatype?
I am specifically thinking about unsigned int. Here is a practical example: what do you do when your identity column maxes out? It’s possible to either go BigInt (8 bytes storage instead of 4) or to refactor the application to support negative integers, and even to create your own rules as indicated in this answer; neither of those options are
Is there a way to list open transactions on SQL Server 2000 database?
Does anyone know of any way to list open transactions on SQL Server 2000 database? I am aware that I can query the view sys.dm_tran_session_transactions on SQL 2005 (and later) database versions, however this is not available on SQL 2000. Answer For all databases query sys.sysprocesses For the current database use:
Need to list all triggers in SQL Server database with table name and table’s schema
I need to list all triggers in SQL Server database with table name and table’s schema. I’m almost there with this: I just need to get the table’s schema also. Answer Here’s one way: EDIT: Commented out join to sysusers for query to work on AdventureWorks2008. EDIT 2: For SQL 2000
SQL Server: Why do use SMO?
I have been working with SQL Server for a couple of years. I have heard about SMO but I don’t know anything about it. What are the benefits of using it? Should I learn and start using SMO in my SQL …
SQL Server SELECT LAST N Rows
This is a known question but the best solution I’ve found is something like: SELECT TOP N * FROM MyTable ORDER BY Id DESC I’ve a table with lots of rows. It is not a posibility to use that query …