sql-server

What is best aproach to get sql data from C#

I'm trying to find optimal (fast vs easiest) way to access SQL Server code thru code in c#. As i was learning from books I've encountered multiple suggestions usually telling me to do it via drag and drop. However since i wanted to do it in code first aproach was to get data by column numbers, but any reordering in SQL Query (like addi...

Determine if a POINT is between two other POINTs on a LINESTRING (SQL Server 2008 Geography)

I have a SQL Server 2008 GEOGRAPHY data type in my database containing a LINESTRING. The LINESTRING describes a potentially curvy road. I have another table that contains a start point and end point, both GEOGRAPHY POINT's, on the road. I need to know if a third point falls between those two points on the road (LINESTRING). Currently, ...

Example SQL Server SQL that uses a formula

I have a table that has a field, call it "score". Is it possible to write an SQL that takes the value in each "score" field, inputs the value in a formula, then the output from the formula is written to another field. I have no experience is using formulas in SQL, and I do not know if its possible. Any basic example, if its doable, would...

Insert into SQL Table Using EnterpriseLibrary?

I have a WCF service which needs to insert into a SQL 2005 log table after successfully executing one of its methods. Using EnterpriseLibrary, I found some sample code which resembles this: public static void SaveActivity(string sSomeString) { Database db = DatabaseFactory.CreateDatabase(); string sInsert = @"INSERT INTO Activ...

SQL Server replication testing

I'd like to write a sql script to do a basic smoke test to check that the replication setup on my server is correct. I think a simple set of CRUD operations against the tables that are supposed to be replicated will achieve what I'm after and I imagine the workflow will look something like this: INSERT a row into a replicated table in...

SQL stored procedure: how do you use the returned value in the same query?

How do I use the value returned by a query in the same procedure? (sorry for noob-ism) I'm trying to get a number of users with an initial beginning with whatever as a list - i.e. A(4) B(2) c(5) etc SELECT DISTINCT LEFT(last_name, 1) AS initial FROM users ORDER BY initial How do I then go on to ask: select COUNT(*) as NumTea...

Example of a very insecure ASP.NET application.

I am looking for a very insecure ASP.NET application. Ideally i'm looking for an application that was written by a noob who has made a lot of security mistakes. If the app has a MS-SQL back-end that would be a bonus. I know of two cool projects for PHP and J2EE which fill my needs. Do you know anything like this for ASP.NET? ...

Do the order of JOINs make a difference?

Say I have a query like the one below: SELECT t1.id, t1.Name FROM Table1 as t1 --800,000 records INNER JOIN Table2 as t2 --500,000 records ON t1.fkID = t2.id INNER JOIN Table3 as t3 -- 1,000 records ON t1.OtherId = t3.id Would i see a performance improvement if I changed the order of my joins on Table2 and Table3. See below: SELECT ...

Updating long string through SQL Server Query Analyzer

I have a really long string of text that I would like to update a particular column in a table. The update statement in sql query analyzer is on one long line currently. Is there a way to break up the update statment into multiple lines for easier reading of the update statement? ...

Update selected records - noob

Hi, Sorry this is a bit of a noob question. I have the following select statement. I would like to update the values of ContactAssociate from 'Bob' to 'Jane'. Is it possible to do this? SELECT TOP (1500) ContactID, ContactNotes, ContactAssociate, ContactAppointment FROM tb_Contact WHERE (ContactAssociate = 'Bob') AND (ContactAppointmen...

UNIQUE - way to have unique rows in table ?

I have problem with unique rows in db table, now it is posible to do that: id | Name | LastName | City ------------------------------------- 1 | John | Moore | London 2 | John | Moore | London when i use UNIQUE attribute in all columns i have errors inserting second Moore even it is different Name :/ how use UNIQUE (...

sql server get only updated record

Hi, I am using sql server 2000. I need to get only updated records from remote server and need to insert that record in my local server on daily basis. But that table did not have created date or modified date field. ...

What is the SQL to create a table where its PK is also a FK?

Say I have: create table Post( PostID int not null constraint PK_Post primary key clustered, Title nvarchar(200) not null ) on [primary] create table PostDetail( PostID int not null constraint PK_PostDetail primary key clustered, Text nvarchar(max) null ) on [primary] How do I make PostDetail.PostID an FK referencing Post.Pos...

how to assign the integer value to nvarchar or varchar datatype in stored procedure

how to assign the integer value to nvarchar or varchar datatype in stored procedure DECLARE @SQLString nvarchar(max) SET @SQLString = N'declare @Identifier int; SELECT COUNT(*) FROM ' + @batch+' where Identifier = @Identifier' i need to check whether the @SQLString is 0 or not. i.e i want to check -----> if(@SQL...

Getting error wile opening the database?

hi, in my system when i am opening the database i get this error like this : Cannot connect to server\sql2005. ADDITIONAL INFORMATION: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not a...

Can I create a VIEW that has a dynamic name in another DB with MS SQL?

I found strange rules in MS SQL CREATE VIEW syntax. It must be on the first line of query batch processing and it must be created in the current database. I should make VIEWs that have dynamic name described by string variables (type: VARCHAR or NVARCHAR). And those VIEWs should be created in other databases. Because of the rule, CREAT...

combine 2 query - sql server 2008 question

I have this query: select count (convert(varchar(50), TmpDate, 103 )),convert(varchar(50), TmpDate, 103 ) from MEN group by TmpDate order by TmpDate desc and I need to count how many rows it returns how I can combine select count (..... and query1 ? I need it in one query thanks in advance ...

SQL Server connection pool doesn't detect closed connections?

For years, I've experienced very weird problems on all my web applications that connect to a SQL server. The problem is that if something happens to the database server (server restart or other problem), de web app stops working from that point on, even if the database server is alive and well afterwards. What happens is that every ADO...

Why do I get "XML parsing: line 2, character 0, incorrect document syntax" when Bulk Inserting in MS SQL Server

I'm doing a BULK INSERT into a table using a FMT format file, but I get the following error: XML parsing: line 2, character 0, incorrect document syntax Here is my code BULK INSERT [DM_Flux].[dbo].[Stage] FROM 'C:\temp\data.dat' WITH (FORMATFILE = 'C:\temp\FormatBcp.fmt') Here is the formatfile (standard format file, not XML): 10...

Alternative to SqlCacheDependency Notification with SQL Server 2005 because of its limitations and still avoid stale data or polling?

Hi geeks, i'm working on a big web project that still keeps evolving, therefor it uses "plain old" sqlcommands, rob connery's subsonic and linq to sql. most queries were written with sqlcommands back then, but new data access methods use linq to sql. we need to cache our data, because the web site is slowing down more and more. because...