sql

Query objects from a Many to Many look-up table

I have Master1 and Sub1 and a another called Master1Sub1_Map which contains foreign keys to the Master1 and Sub1 objects. There are multiple ID's from Sub1 that are associated with a single id in Master1. If I want to see all the Sub1 records that are assigned to a specific Master1.ID how do I go about doing that with the SubSonic obje...

How can i join #Temp with sql table?

How can i join ( or union) #Temp with scr_SecuristLog Time. Look please [Time] column CREATE TABLE #Temp (VisitingCount int, [Time] int ) DECLARE @DateNow DATETIME,@i int,@Time int set @DateNow='00:00' set @i=1; while(@i<48) begin set @DateNow = DATEADD(minute, 30, @DateNow) set @Time = (datepart(hou...

Time out period not elapsed, but still timing out (see code)?

OK I keep getting this error after about 3-4 minutes of churning: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the e...

Select n random rows from SQL Server table

I've got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I've thought of a complicated way, creating a temp table with a "random number" column, copying my table into that, looping through the temp table and updating each row with RAND(), and then selecting from that table where the ...

Calculating in SQL the first working day of a given month

Hi! I have to calculate all the invoices which have been paid in the first 'N' days of a month. I have two tables . INVOICE: it has the invoice information. The only field which does matter is called 'datePayment' . HOLYDAYS: It is a one column table. Entries at this table are of the form "2009-01-01", 2009-05-01" and so on. I shou...

Connect different Windows User in SQL Server Management Studio (2005 or later).

Is there a way in SQL Server Management Studio 2005 (or later) to change the Windows Authentication user (as you could in SQL Server 2000 and older)? This is the general connection properties dialog I am referring to (note the greyed out UID/PWD when selecting Windows Auth; sorry, I'm new so can't embed an img). FYI - One workaround is...

Approaches to building reports with Quickbooks 2008+ Data

I am looking to build some reports for Quickbooks data, without using Quickbooks built-in reporting, or through a third party library (like QODBC). Quickbooks 2008 and newer are built on a SQL backend.. In looking around there seems to be several products and angles to do this from. Ideally I would like to be able to do direct SQL hit...

How can I get SSIS Lookup transformation to ignore alphabetical case?

Hopefully this is easy to explain, but I have a lookup transformation in one of my SSIS packages. I am using it to lookup the id for an emplouyee record in a dimension table. However my problem is that some of the source data has employee names in all capitals (ex: CHERRERA) and the comparison data im using is all lower case (ex: cherrer...

SQL Server Management Studio Display Database Diagrams (ER) Permissions

I was wondering if anybody knew exactly what permissions where needed on a database in SQL Server 2005+ so that when a person uses SQL Server Management Studio, they could then be able to at minimum see the Database Diagrams. I have tried giving the person db_datareader, db_datawriter, and db_ddladmin, but to no avail. I have also tr...

Easy way to see SQL generated by ActiveRecord.Save()?

SubSonic 2.1 I have an ActiveRecord object. When I call its Save() method, is there an easy way for me to seen the generated SQL, say in the Visual Studio debugger? Running SQL Profiler is not an option. Thanks. ...

How to manage "groups" in the database?

I've asked this question here, but I don't think I got my point across. Let's say I have the following tables (all PK are IDENTITY fields): People (PersonId (PK), Name, SSN, etc.) Loans (LoanId (PK), Amount, etc.) Borrowers (BorrowerId(PK), PersonId, LoanId) Let's say Mr. Smith got 2 loans on his name, 3 joint loans with his wife,...

What's the most efficient way to insert thousands of records into a table (MySQL, Python, Django)

Hello, I have a database table with a unique string field and a couple of integer fields. The string field is usually 10-100 characters long. Once every minute or so I have the following scenario: I receive a list of 2-10 thousand tuples corresponding to the table's record structure, e.g. [("hello", 3, 4), ("cat", 5, 3), ...] I nee...

Should I build a recordset first or just insert the data?

I'm consuming a web service using a stand-alone VBScript. The web service returns to me a list of jobs, which I need to loop through and add to a SQL database. I can either Run through the nodelist, reading the data and actioning the SQL insert in the loop. or Run through the nodelist building a recordset, then run through the recor...

How to insert into a table with just one IDENTITY column

(Came up with this question in the course of trying to answer this other one) Consider the following MS-SQL table, called GroupTable: GroupID ------- 1 2 3 where GroupID is the primary key and is an Identity column. How do you insert a new row into the table (and hence generate a new ID) without using IDENTITY_INSERT ON? N...

returning partially distinct/unique rows

Hi all, I need to create a query which groups by two columns and returns an additional column based on a condition. For example, say I've got the following columns: ProductCode | SerialNumber | Quantity | DatePurchased | CustomerID and the table contains duplicate combinations of ProductCode and SerialNumber with differing Quanitite...

What are the system tables used in Sql Server replication?

What are the system tables used in Sql Server replication? ...

Storing time-temperature data in DB

I'm storing time-temperature data in a database, which is really just CSV data. The first column is time in seconds, starting at zero, with the following (one or more) column(s) being temperature: 0,197.5,202.4 1,196.0,201.5 2,194.0,206.5 3,192.0,208.1 ....etc Each plot represents about 2000 seconds. Currently I'm compressing the ...

WHERE Clause to find all records in a specific month

I want to be able to give a stored procedure a Month and Year and have it return everything that happens in that month, how do I do this as I can't compare between as some months have different numbers of days etc? What's the best way to do this? Can I just ask to compare based on the year and month? Thanks. ...

Min effective and termdate for contiguous dates

Hi, Is there w way to achieve following using an SQL 2000 query, i looked everywhere but could not find any working snippet. I have contiguous date segments and requirement is to get the min effective date and maximum effective dates for each contiguous dates. if that is not possible getting min effective date and max termdate for an ...

Nested transactions in sql server

Does sql server allow nested transactions? If so then whats the priority of transactions? ...