sql

SQL Looping

I'm building this report in a system for a Billboard company. They have a table that stores all their billboards, and among other data, billboards have a Start Date and a Finish Date (both can be null). If for some reason a billboard has to stop beeing used, they set a finish date and it will become unnavaiable to be used after that date...

Transact-SQL shorthand join syntax?

I have noticed a few times when working on legacy code, that you can do left and right outer joins in sql by using the =* as kind of shorthand for "right outer join" and *= as kind of shorthand for "left outer join" in statements like this: select table1.firstname, table2.lastname from table1, table2 where table1.id *= table2.id ...

How to write "Tagging" query in SQL?

Hi, I am adding "Tagging" functionality in my web app. My applications table structures are as following; Tag: (TagId INT IDENTITY, TagName VARCHAR(60)) TaggedRecords: (TaggedId INT IDENTITY, TagId, TaggedRecordId) Now, I want when anyone adds a tag to any record then following action should be performed using a single sql query...

How should you deal with data for multiple prices for a single product?

Each product in my database can have at least three and sometimes four or five different prices, and which one is displayed is based on several factors. How should I attempt to tackle this scenario? Each product can have the following prices: List Price (MSRP) Cost (what we pay for it) Retail Price - shown on "main" site Government p...

how to access sql server from asp page

We have a legacy, homegrown timesheet system (ASP, microsoft sql server 2005) that I need to clone to another computer for backup purposes. (I know very little about this stuff, so pleas be gentle) I've got most of the pieces in place (IIS, Sql Server, table import / creation). But, the ASP page to access the timesheet pages is choking ...

Can you create a new SQL buffer in Emacs if one already exists?

Let's say you have a *SQL* buffer already open in Emacs that is connected to a specific server and database. Now, your intention is to connect to a different server and database while keeping your other SQL buffer process active. How exactly can you create a new *SQL* buffer process without killing your original SQL buffer? Can this b...

How do I find all references from other tables to a specific row?

So I have an address table that is shared among various other tables, such as schools, parks, churches, etc. Schools, parks, etc all foreign key to a row in address. What I'm wondering is, if I have a specific row in the address table, is there a way to find out which row in which table points to it. So basically just this: SELECT *...

How do I condense this SQL of multiple sub-selects into something more sane?

The following query returns a single row, as desired. The 'contracts' table has 6 fields, each with a different username in it, for which I want to retrieve first/last names from a separate 'users' table. This works fine, but is there something more concise? I'm think the solution must be something using GROUP BY contracts.id to keep ...

full-text index not updating (SQL 2005)

I have a table that was doing a fine job of full-text search until last week. There are over seven million records, and I see it has over seven million entries in the full-text index. But nothing more recent than a week old shows up in the search results. I can see in the table's full-text index properties that there are a growing n...

Why am I getting a multi-part identifier error in SQL?

There are some tables that we want to do a search I couldn't understand why this error happens , please help I should be easy for experts , SELECT * FROM passenger INNER JOIN [passenger-flylist] ppff ON ppp.[passenger-id] = ppff.[passenger-id] the Error : Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "ppp.passenger-i...

SQL query to return top N rows per ID across a range of IDs

Lets say I have a table containing several hundred million rows that looks something like this: memID | foo | bar | foobar 1 | blah | blah | blah 1 | blah | blah | blah 1 | blah | blah | blah 1 | blah | blah | blah 1 | blah | blah | blah 1 | blah | blah | blah 1 | blah | blah | blah 2 | blah | blah | bl...

Is it always necessary to create Dim tables?

I have a fact table that will have a column which will hold one of two values (occupied/vacant). Is it necessary to create a Dim table for this? ...

SQL Convert float to comma varchar with decimals

I have a couple floats that are kinda big. They're around a 100 million. I would like this number to show like the following 123,456,789.01234 I've found that I can use CONVERT if its a money datatype but this doesn't do the full trick (it leaves off some decimal places). I have to have commas on the left and five decimal places on th...

Should I use one LINQ DataContext or many?

For a large project, would it make sense to have one datacontext which maps out your database, which you can interact with from your classes? Or would it make more sense to split this up into small datacontexts which are focused on the specific tasks within the database that will be required. I'm curious as to the performance. It's my...

Oracle Database 10g VIEW performance

Hello, I have a view in one of my Oracle Database that is taking too long to execute. When the statement runs, it does not seem to stop. Is there anyway that we can verify the performance of this view or how we can check to see if the statement session is 'hanging'? Thanks, N2EE UPDATE I realised that the issue is with the underlyin...

Microsoft SQL Server 2008 External Backup

Hi, I would like to save my backups from my SQL 2008 server to another server location. We have 2 servers: Deployment server File Server The problem is that the deployment server doesn't have much space. And we keep 10 days backups of our databases. Therefore we need to store our backups on an external "file server". The problem is ...

How would you maintain a history in SQL tables?

Hi all, I am designing a database to store product informations, and I want to store several months of historical (price) data for future reference. However, I would like to, after a set period, start overwriting initial entries with minimal effort to find the initial entries. Does anyone have a good idea of how to approach this proble...

Performance of data

I have 60 columns in a table. 1). I want to add one more column to that table. Will there be any impact on performance? 2). How many columns can I add? 3). any idea for the avoid recursion. [I have no idea here - annakata] ...

How can I take each array item and insert in a SQL database?

I have the following vb.net code to take the values out of a textbox on a webpage (actually space delimited tags) and split them with a space delimiter into an array. This works exactly how I want. mySample.Tags = tagsTextBox.Text Dim tags As String = mySample.Tags Dim tagarray() As String Dim count As Integer tagarray = tags.Split(" ")...

How do I handle long comparisons in SQL

I have a pathological issue with SQL, so I usually sort all of my database issues by building quickie software applications to handle my SQL problems. (as I am also doing in this case) Thanks to StackOverflow I think I can be shamed into correctness, so I would like to learn how to make this kind of SQL troubleshooting in actual SQL o...