What's the best way to determine if a given SQL Server table is readonly, either because of account permissions or the database being marked as read-only?
I'm trying to select records with a statement
SELECT *
FROM A
WHERE
LEFT(B, 5) IN
(SELECT * FROM
(SELECT LEFT(A.B,5), COUNT(DISTINCT A.C) c_count
FROM A
GROUP BY LEFT(B,5)
) p1
WHERE p1.c_count = 1
)
AND C IN
(SELECT * FROM
(SELECT A.C , COUNT(DISTINCT LEFT(A.B,5)) b_count
FROM A
GROUP BY C
) p2
WHERE p2.b_count = 1)
which takes a long time to run ~15 sec.
Is there a better way of writing this SQL?
I'm trying to execute a SELECT statement that includes a column of a static string value. I've done this in Access, but never with raw SQL. Is this possible?
Example:
Name Status
John Unpaid
Terry Unpaid
Joe Unpaid
In the above example, the "Status" column doesn't exist in the database.
I have re-written my code after great help from some friendly stack overflow members (big thanks to Martin B and Kev Chadders especially). I would now like to check if my code is still open to SQL Injections after this work. I believe the code is now working as it should, but any blinding errors that you see i'd love to hear about too. My code is now looking like:
-code removed-
If I have an UDF that returns a table, with thousands of rows, but I just want a particular row from that rowset, will SQL Server be able to handle this effciently?
SELECT * FROM dbo.MyTableUDF()
WHERE ID = 1
To what extent is the query optimizer capable of reasoning about this type of query?
How are Table-Valued UDFs different from traidtional views if they take no parameters?
Any gotchas I should know about?
Please, give me the most serious arguments against this.
Application directly opens a connection to ms sql server, directly executes queries.
So what I'd like to ask:
1) Why it is wrong?
2) What serious problems can that cause?
3) What should I do?:)
Cursor cursor = db.rawQuery("SELECT COUNT(rat)
FROM "+ TABLE_NAME_EXTRA +" apkid=\""+apkid, null);
cursor.moveToFirst();
int somatotal = cursor.getInt(0);
I'm trying to do a SQL function like count and sum, but this code returns a exception saying "emptyvalues".
anyone know why?
I am very new to SQL Server Stored Procedures,
I am trying to create a SP that will give return a list of records in a table by filter via StartDate and EndDate , but there will be 'View All' Option so sometime those @Param might not contain any values.
Currently my SP is Like
CREATE PROCEDURE [dbo].[spGetBonusRun]
(
@StartDate as DATETIME,
@EndDate as DATETIME
)
AS
SELECT [Id]
,[StartDateTime]
,[EndDate]
,[Status]
FROM [Valt].[dbo].[BonusRun]
WHERE StartDateTime <= @StartDate AND EndDate >= @EndDate
How to active that ?
I have a SQL query in my ASP.net web app that looks like this:
SELECT * FROM [Records] WHERE ([title] LIKE '%' + @title + '%')
@title, of course, is the value of a text box on the page.
My question is, why, when the text box is empty, does this return nothing? And how can I make it return everything, like logic tells me it ought to?
We are having problems on one machine, with the error message:
"MSDTC on server XXX is unavailable."
The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction.
As only a single sql database (2005) is being accessed, why is a distributed transaction being used at all?
(I don’t wish to know how to enable MSDTC, as the code needs to work on the server with their current setup)
I have the same query in a stored procedure that needs to be executed on different servers and databases according to parameters.
How can I arrange this without exec or sp_executesql?
I'm using SQL Server 2008.
Thank you.
Hi,
While working with DB, I find useful using some tools, that help me to solve DB problems.
Some of them are:
1) Insert generator
2) A tool that can execute a script on a list of DB's
3) Finding a text in stored procedures and functions.
4) DB Back up scripts
My question is, what are most useful tools, scripts(anything else), that help you to work with MS SQL?
Thanks in advance.
I am trying to set up a device remotely. I found this link:
http://www.microsoft.com/downloads/details.aspx?familyid=FCE9ABBF-F807-45D6-A457-AB5615001C8F&displaylang=en
That has SQL Server CE 3.5 SP1. I read the whole page, and can't seem to find out for sure if SP1 is a full install or if it needs SQLServer CE 3.5 first.
Does anyone know?
In Microsoft SQL, is there any difference in performance between this:
SELECT columns FROM table1 WHERE cond
UNION
SELECT columns FROM table2 WHERE cond
and this:
SELECT columns FROM
(
SELECT columns FROM table1
UNION
SELECT columns FROM table2
) WHERE cond
?
Please help me with writing a sql query - I have a table with id, name and marks columns.
If I arrange the table in ascending order of marks, how can I fetch 5 names whose marks are close to a particular name.
We have a server with a database that has a symmetric key (Database - Security - Symmetric Key). We have a backup duplicate databases that we are using as a test databases, but we don't have this key in there.
How can I duplicate this symmetric key and put it in the existing databases? It has to have the same value and key-name as the other one.
This is on MS SQL Server 2008 .
Hi
I have the following SQL SELECT statement
SELECT bar_id, bar_name, town_name, advert_text
FROM bar, towns, baradverts
WHERE town_id = town_id_fk
AND bar_id = bar_id_fk
My problem is that since not every bar has an advert in table "baradverts", these bars are not coming up in the results. In other words I need a NULL for those bars that do not have an advert string.
Hi,
I am using SQL server 2008 express and some of our columns are defined as varchar(255). Should I convert these columns to NvarChar(255) or nvarchar(max)?
The reason I ask is I read that nvarchar(255) for unicode characters would actually store 1/2 the number of characters (since unicode characters are 2 bytes) whereas 255 with varchar() would allow me to store 255 characters (or is it 255 - 2 for the offset).
Would there be any performance hits using nvarchar(max)?
JDs
As I know, from the relational database theory, a select statement without an order by clause should be considered has not particular order. But actually in SQL Server and Oracle (I've tested on those 2 platforms), if I query from a table without an order by clause multiple times, I always get the results in the same order. Does this behavior can be relied on? Anyone can help to explain a little?
Thanks!
Hi
I am getting
Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
When I run the SAME query in the SQL query program I get result within seconds, and in LINQ it takes forever and fails.
What can cause this???
Thanks!
Hello, I have a system with 3 layers and I am using LINQ-to-SQL to persist.
I want to validate if the description field of my object is empty. I am using partial classes and the method OnValidate(). If the field is empty, it throws an exception.
Is this correct?
What do I do after the exception to not close the form, letting the user continue working?
Thank you very much
Sorry for my poor english
Hi everyone,
I want to add service reference to SQL reporting services on local machine. In Reporting Service Configuration Manager under Web Service URL tab I have report service URL exposed, I have tried to add web reference to project with that Web Reference URL, but it can not be found.
Please tell me am I missing something or is this right way to to?
Thanks a lot.
Hi Team,
Could you please list some of the bad practices in SQL, that novice people do?
I have found the use of "WHILE loop" in scenarios which could be resolved using set operations.
Another example is inserting data only if it does not exist. This can be achieved using LEFT OUTER JOIN. Some people go for "IF"
Any other thoughts?
Thanks
Lijo