sql

stop SQL service in c#

I have installed 2 servers for Microsoft SQL 2008. The first one is MSSQLSERVER and second one is SQL2008. When I tried to stop the first one it stopped but the second one not the VS told me that this service not found ServiceController svc = new ServiceController("SQL2008", Process.GetCurrentProcess().MachineName); svc.Stop() So...

how to check the condition in sql server?

Table 1 slitem firstname lastname 1 aaa bbb Table 2 slitem firstname lastname 1 null null 2 null null Result : slitem firstname lastname 1 aaa bbb 2 null null i want to join this two table.... help me ...

SQL - counting based on multiple criteria

I've written SQL count statements before but I need to write a query which returns 2 sets of count values for a condition. The original query counts the amount of people for a company who have invalid information, fine, works great. I now need to extend this query so that it performs the above operation but also includes the total count ...

SQL - Patient with an office visit one year before the most recent one

I'm trying to write a query that brings back patients who have had an office visit at least a year before the most recent one. The various ways I'm thinking of get all twisted up in my head, so I was wondering if anyone out there can see an obvious way to write it that I'm missing. Don't worry too much about the exact syntax and naming -...

SQL Server: need to add a primary key

I have about 5000 records in a table in SQL Server 2008 I need to add a primary key. I don't care what it is, maybe an autonumber would be best? How do I add a primary key to every record ? I also would like this primary key to be generated automatically when I add new rows! ...

SQL Select Master Records and Display Number of Detail Records for Each

I have a Master and Detail table, the Detail linking to the Master record on a FK reference. I need to display all the data from the Master table, and the corresponding number of details for each record, i.e. MASTER TABLE ID Name Age 1 John 15 2 Jane 14 3 Joe 15 DETAIL MasterID Subjects 1 Trigonometry 1 Chemistr...

How can I prevent attacks on my SQL Server installation?

In the past month I've noticed in my event viewer on a sql server a lot of failure audits. Seems like a brute force attack from an ip in china trying to log in to the sa account which i have disabled. I've blocked it on my network firewall but then a week later i'm getting the same attack from another ip also based in china. So far i've ...

Is there a better way to find anagrams using SQL?

Given the following database table: WORDS alphagram....varchar(15) word.........varchar(15) PK length.......int Where: 'alphagram' is the letters of a word in alphabetical order (e.g. AEINNRTT is the alphagram of INTRANET) the primary key is 'word', and there are indexes on alphagram and length I've found a way to find the ana...

Materialized views with MySQL

Emulated materialized views with MySQL has good performance? I'm learning how to do with this link thanks Correction: "Materialized views" to "Emulated materialized views". ...

sql-server: how do i know who is in my database?

i have an access front end and sql server backend. i would like to know which users are currently using the database. is this possible to do using access or sql-server? ...

ms-access: how to do a proper requery?

i am distributing ms-access-2007 front ends. the back end is sql server. a user will click on a button and it will return a query from the sql server 2008 database. is it possible to requery this query if the user clicks the button again? usually the behavior of access is that if you query it again, it displays old results. how do i m...

SQL is only reading 1 UserID When I'm Requesting A Picture + Name from the ID. Wondering Why

I have an asp repeater reading a datasource and it's linked eventually to this code through the code behind [dbo].[GetFeatStatic] AS BEGIN DECLARE @FeaturedStatic TABLE ( UserID INT, UserTitle varchar(50), Title varchar(50), Summary text, DatePosted date, FirstName varchar(50), LastName varchar(50...

Requiring parameters in a SQL where clause?

Imagine you have the following table (note: this is a contrived/simplified example): CREATE TABLE foo ( book_id number, page number, -- [a bunch of other columns describing a single page in a book] ); ALTER TABLE foo ADD (CONSTRAINT foo_pk PRIMARY KEY(book_id, page)); While (book_id, page) pairs are unique, the same page nu...

SQL Query Error

What is wrong with this Query? INSERT INTO Registration (`Status`, `String`) VALUES ('Confirmed', '0') WHERE `String` = '". mysql_real_escape_string($user) ."' 1A: UPDATE Registration `Status` = 'Confirmed', `String` = '0' WHERE `String` = '". mysql_real_escape_string($user) ."' ...

access: how to detect with VBA whether a query is opened?

is it possible to detect whether there is an open query using VBA in access-2007? i am opening a query like this: stDocName = "Meeting_Reasons_Frequency" DoCmd.OpenQuery stDocName is it possible to detect whether it is open? ...

Parse column value based on delimeters

Here is a sample of my data: ABC*12345ABC BCD*234() CDE*3456789(&(& DEF*4567A*B*C Using SQL Server 2008 or SSIS, I need to parse this data and return the following result: 12345 234 3456789 4567 As you can see, the asterisk (*) is my first delimiter. The second "delimiter" (I use this term loosely) is when the sequence of numbers ST...

Oracle show all employees with greater than average salary of their department.

I am writing a query to find employees who earn greater than the average salary within their department. I need to display the employee ID, salary, department id, and average salary of that department. I have a query that just almost works but it keeps giving me "ORA-00904: "AVG_SAL": invalid identifier" errors. Am I doing this correctl...

How to replace common words in sql column

I have a table of common words that are used in sentences (i.e. A, the, and, where, etc...) What I want to do is loop through all those words and strip them out of the descriptions that people have entered to attempt to generate common keywords or tags. But I can't use replace because replace will remove any instance of the common word ...

SQL statement joing Oracle and MS SQL Server

I never seen this, but is it possible to have one SQL call join data from Oracle and SQl Server? ...

Using DateTimeOffset as WHERE criteria in a SQL Server 2008 query

Hi Everyone, I was wondering if anyone could help me understand why these two criteria do not return the same result sets. To me, it seems weird that SQL Server 2008 R2 wouldn't know to use the offset while constraining the data. Is there a better way to do this? As far as I can tell, Criteria Two is the only way to get the correct data...