sql

Visual Studio syntax highlighting

Is it possible to get the same level of syntax highlighting in Visual Studio 2008, that SQL Server Management Studio has? This is regarding T-SQL. For example SSMS has separate highlighting options for operands, system functions etc, while Visual Studio 2008 only seems to have one 'keyword' for T-SQL. ...

Dynamic SQL Comma-Delimited Value Query

[Update: Using SQL Server 2005] Hi, what I want to do is query my stored procedure with a comma-delimited list of values (ids) to retrieve rows of data. The problem I am receiving is a conversion error: Conversion failed when converting the varchar value ' + @PassedInIDs + ' to data type int. The statement in my where-clause and e...

How would you make a Temporal Many-to-Many Relationship in SQL?

How would you represent a temporal many-to-many relation in SQL? Under non-temporal circumstances one would use a junction table (aka link/bridge/map) to connect the two sides. Is adding temporal tracking as simple as including a ValidStart and ValidEnd columns on the junction table? If you have done this, what issues (if any) did you r...

Why would a sql query have "where 1 = 1"

I was going through a few queries I am maintaining, and a programmer had put in the queries "where 1=1" to me that always seems to evaluate to true. Are there benefits to this? Duplicate: Why would someone use WHERE 1=1 AND in a SQL clause? That question isn't an answer to this question. Where-clause: select * from table where 1...

User Granted Access to Stored Procedure but Can't Run Query

I am working on a product that runs an SQL server which allows some applications to login and their logins are granted permission to run a stored procedure- AND NOTHING ELSE. The stored procedure is owned by an admin; the stored procedure takes a query and executes it, then the results are returned to the application. Unfortunately I c...

Is there ever a time where using a database 1:1 relationship makes sense?

I was thinking the other day on normalization, and it occurred to me, I cannot think of a time where there should be a 1:1 relationship in a database. Name:SSN? I'd have them in the same table PersonID:AddressID? Again, same table. I can come up with a zillion examples of 1:many or many:many (with appropriate intermediate tables), bu...

Select Primary Key

[UPDATE: MS SQL Server 2005] Hi is it possible to select a bunch of values, and then assign a column in the select statement as the primary key? SELECT ID FROM HQ AS PRIMARYKEY -- this is wrong SELECT Names FROM Stores SELECT PRODUCTNAME FROM PRODUCTS I ask this because I want to take advantage of the DataRow find method in .net, tha...

Meaning of (+) in SQL queries

I've come across some SQL queries in Oracle that contain '(+)' and I have no idea what that means. Can someone explain its purpose or provide some examples of its use? Thanks ...

Strings as Primary Keys in SQL Database

I am not very familiar with databases and the theories behind how they work. Is it any slower from a performance standpoint (inserting/updating/querying) to use Strings for Primary Keys than integers? ...

3 Tables, left outer join, SUM

I'm having a problem with my LEFT OUTER JOIN on 3 tables, with a SUM clause. This is my code: SELECT r.ret_desc, vmp.vlt_id, SUM((vmp.cash_in + vmp.per_cash_in_sec) + (CASE WHEN vmp.acc_id = t.db_id AND t.txn_type_id = 1 THEN t.amount ELSE 0 END) - (CASE WHEN vmp.acc_id = t.cr_id AND t.txn_type_id = 1 THEN t.amount ELSE 0 END)) AS...

Is it possible to use output parameters with ExecuteQuery<T>?

Normally, when you want to call a stored procedure directly through Linq to Sql, you can use the ExecuteQuery method: result = dc.ExecuteQuery<MyTable>("Exec myStoredProcedure"); And if you need to call it with parameters, you can add them through string substitution: string query = "Exec myStoredProcedure "; for (int i = 0; i < para...

Select Top (all but 10) from ... in Microsoft Access

Say I've got a query SELECT TOP 10 ... FROM ... ORDER BY ... in Access (well, really Jet). The question is: how can I get all the other rows... everything except the top 10? ...

Retrieve column names from a different table?

I have a "datadump" table that has a bunch of mixed performance-related data. Something like: MachID TestDate MachType Value1 Value2 ... 00001 01/01/09 Server 15 48 00001 01/02/09 Server 16 99 19999 01/01/09 Switch 32 4.9880 19999 01/02/09 Switch 32 5.8109 ...

Zip Code to City/State and vice-versa in a database?

I'm new to SQL and relational databases and I have what I would imagine is a common problem. I'm making a website and when each user submits a post they have to provide a location in either a zip code or a City/State. What is the best practice for handling this? Do I simply create a Zip Code and City and State table and query against...

List active forum threads

$sql = mysql_query("SELECT * FROM posts WHERE post_content = 'thread' ORDER BY post_date DESC LIMIT 65"); while($row = mysql_fetch_array($sql)){ echo "$row['post_contentID']"; } I'm want to list forum threads that there has recently been posts posted in. The "problem" is that it lists the same thread more than once. If I have posted...

How do you catch exceptions with "using" in C#

Given this code: using (var conn = new SqlConnection("...")) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "..."; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { // ... } } } } I'm used to ...

How to design a database table structure for storing and retrieving search statistics?

I'm developing a website with a custom search function and I want to collect statistics on what the users search for. It is not a full text search of the website content, but rather a search for companies with search modes like: by company name by area code by provided services ... How to design the database for storing statistics ...

SQL List Function Removing Precision

I am using the LIST function to create a ';' delimited list of values. The type is numeric (19,2). For some reason the precision appears to be ignored when using the list function. When performing a simple select on this column the values look good, ie "12.00". However, if I use a LIST() my results are of format "12.000000" This is my L...

SQL Count() question

I have a table with a charge/credit column: Item | PriceVal | CostVal | CHARGE_CODE 1 5 3 CH 2 8 5 CH 1 -5 -3 CR 3 7 1 CH 4 15 10 CH 1 5 3 CH I've got the query I need to get th...

How to debug stored procedures in Sybase ASE?

Is there a good tool from either Sybase or elsewhere that will enable me to debug stored procedures in Sybase ASE? I need to be able to set breakpoints & watchpoints. Previously, in Sybase ASA (not ASE), I used Sybase Central to do this. There is a plugin for ASE, but I doubt it will let me debug procedures. ...