I was wondering if it’s possible to do something like this (which doesn’t work): select cast( (exists(select * from theTable where theColumn like ‘theValue%’) as bit) Seems like it should be doable, but lots of things that should work in SQL don’t 😉 I’ve seen workarounds for this (SELECT 1 where… Exists…) but it seems like I should be able
Tag: tsql
Why do I get “Procedure expects parameter ‘@statement’ of type ‘ntext/nchar/nvarchar’.” when I try to use sp_executesql?
Why do I get this error Procedure expects parameter ‘@statement’ of type ‘ntext/nchar/nvarchar’. when I try to use sp_executesql? Answer Sounds like you’re calling sp_executesql with a VARCHAR statement, when it needs to be NVARCHAR. e.g. This will give the error because @SQL needs to be NVARCHAR So:
How to find Expr#### in Execution Plan
When looking at the actual execution plan for a query in SQL Server Management Studio (SSMS), how do I determine what an expression such as Expr1052 represents? When I identify the costly parts of the query and look at the properties of that operation, there are often references only to these Expressions, or scalar operators. I want to be able
Sql select rows containing part of string
I want to write a comparation procedure (t-sql) for site seo. I have a table with field ‘url’ (nvarchar()) that contain a part of site url’s. Ex: ‘mysyte.com/?id=2’. Also this table for each url contains metadata, that i need to extract. The main problem is that full url on site looks like ‘mysyte.com/?id=2®ion=0&page=1’, and i just need to ignore everething,
How do I UPDATE from a SELECT in SQL Server?
In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement: Is it also possible to update a table with SELECT? I have a temporary table containing the values and would like to update another table using those values. Perhaps something like this: Answer
How to Join to first row
I’ll use a concrete, but hypothetical, example. Each Order normally has only one line item: Orders: OrderGUID OrderNumber ========= ============ {FFB2…} STL-7442-1 {3EC6…} MPT-…
Trunc(sysdate) in SQL Server
What is the equivalent of: …in SQL Server 2005? Answer Recommended: This is another alternative, but it’s risky because of casting to a FLOAT. It’s also been demonstrated to not scale performance as well as the DATEADD/DATEDIFF approach.
How do I compare two columns for equality in SQL Server?
I have two columns that are joined together on certain criteria, but I would also like to check if two other columns are identical and then return a bit field if they are. Is there a simpler solution than using CASE WHEN? Ideally I could just use: Answer What’s wrong with CASE for this? In order to see the result,
SQL : BETWEEN vs =
In SQL Server 2000 and 2005: what is the difference between these two WHERE clauses? which one I should use on which scenarios? Query 1: Query 2: (Edit: the second Eventdate was originally missing, so the query was syntactically wrong) Answer They are identical: BETWEEN is a shorthand for the longer syntax in the question that includes both values (EventDate
How do I return the SQL data types from my query?
I’ve a SQL query that queries an enormous (as in, hundreds of views/tables with hard-to-read names like CMM-CPP-FAP-ADD) database that I don’t need nor want to understand. The result of this query needs to be stored in a staging table to feed a report. I need to create the staging table, but with hundreds of views/tables to dig through to