sql

Clearbox Radius attributes through SQL statement?

I authenticate users through Radius, and I have the option to assign Radius attributes through SQL statements, but I can't for the life of me find any documentation on this. Anyone know the proper syntax? ...

IBM DB2 LPAD/RPAD

I use db2 v.9.1 on windows 2003 server so it can not use LPAD or RPAD functions scalar. because that functions support only z/OS right? Now, I use this way for pad zero when COLUMN1 type is VARCHAR RIGHT('0000' || COLUMN1 ,4) AS RPAD LEFT('0000' || COLUMN1 ,4) AS LPAD Have better way for replace LPAD or RPAD function? ...

SQL Export to Excel results to doc lock, cannot edit the sheet

Hi, please help me solve the following issues. When I export a report from SQL reports 2005 the image logos are distorted a bit, and the sheets are locked so further editing and sorting is not possible. When I unlock the the frozen cells, to allow sorting and editing, the whole sheets are scrambled due to merged cells used by headings...

SQL: Select "until"

I'm looking for a way to select until a sum is reached. My "documents" table has "tag_id" and "size" fields. I want to select all of the documents with tag_id = 26 but I know I can only handle 600 units of size. So, there's no point in selecting 100 documents and discarding 90 of them when I could have known that the first 10 already ...

How can you find the number of occurrences of a particular character in a string using sql?

How can you find the number of occurrences of a particular character in a string using sql? Example: I want to find the number of times the letter ‘d’ appears in this string. declare @string varchar(100) select @string = 'sfdasadhfasjfdlsajflsadsadsdadsa' ...

Why do people hate SQL cursors so much?

I can understand wanting to avoid having to use a cursor due to the overhead and inconvenience, but it looks like there's some serious cursor-phobia-mania going on where people are going to great lengths to avoid having to use one for example, one question asked how to do something obviously trivial with a cursor and the accepted answer...

SQL: What's the difference between HAVING and WHERE?

I must be googling in the wrong way or I'm having a stupid moment in time. What's the difference between HAVING and WHERE in an SQL SELECT statement? EDIT: I've marked Steven's answer as the correct one as it contained the key bit of information on the link: When GROUP BY is not used, HAVING behaves like a WHERE clause The situat...

Is it safe to use MS SQL's WITH (NOLOCK) option for select statements and insert statements if...

Is it safe to use MS SQL's WITH (NOLOCK) option for select statements and insert statements if you never modify a row, but only insert or delete rows? I..e you never do an UPDATE to any of the rows. ...

query join question

I have a right outer join, that almost does what I want... SELECT users_usr.firstname_usr, users_usr.lastname_usr, credit_acc.given_credit_acc, users_usr.created_usr, users_usr.sitenum_usr, users_usr.original_aff_usr, users_usr.id_usr FROM credit_acc right Outer Join users_usr ON credit_acc.uid_usr = users_usr.id_usr The problem is, I...

SQL inline if statement type question

Hi, I'd like to make an (MS)SQL query that returns something like this: Col1 Col2 Col3 ---- --------------------- ------ AAA 18.92 18.92 BBB 20.00 40.00 AAA 30.84 30.84 BBB 06.00 12.00 AAA 30.84 30.84 AAA 46.79 46.79 A...

Oracle SQL Optimization: SQL Query taking very long time

SELECT DISTINCT 'LRS-TECH 1' || rpad(code,7) || rpad('APPTYPE',30) || rpad(licensing_no,30) || rpad(' ',300) AS RECORD FROM APPS WHERE L_code = '1000' AND licensing_no IS NOT NULL This seems to be the primary culprit in why I cannot export these records to a textfile in my development environment. Is there any way I can ge...

Dynamically built SelectCommand for GridView SqlDataSource in asp.net

I'm working with a GridView that uses a SqlDataSource element that looks like this: <asp:SqlDataSource ID="InventoryDB" runat="server" ConnectionString="<%$ ConnectionStrings:InventoryConnectionString %>" SelectCommand="SELECT [Server], [Customer] FROM [Website] WHERE [Owner] = 'someOwner'"> </asp:SqlDataSour...

What's the best data type for a 1 character code column in a SQL table?

this is not a primary key, but merely used as a marker in existing system that marks these items with a 1 letter code ie 'N' for new, 'R' for return, etc. I was going to go with a varchar(50) as the data type but wondering if there's anything wrong with say varchar(2) instead aiming for efficiency. thx! ...

Dynamically Generated Datatable for Google's Annotated Time Line

I want to use Google's Annotated Time Line Visualization. It is very easy to make this work by manually adding the lines for column & row data. This is all done through attributes of google.visualization.DataTable(). I would like to update this data table dynamically, but I do not know how. The data is on a server running MS SQL Server ...

What GOOD tools are available for generating ERD from a SQL Server Database?

I am trying to generate an Entity Relationship Diagram from an existing MS SQLServer 2005 database. What tools are available? Specifically,I am not only interested in ERD's more directly I am looking for a tool to help quickly learning and analysing a medium size (schema wise not really row wise) database structure. ...

SQL: Get all posts with any comments

I need to construct some rather simple SQL, I suppose, but as it's a rare event that I work with DBs these days I can't figure out the details. I have a table 'posts' with the following columns: id, caption, text and a table 'comments' with the following columns: id, name, text, post_id What would the (single) SQL statement ...

Update multiple values in a single statement

I have a master / detail table and want to update some summary values in the master table against the detail table. I know I can update them like this: update MasterTbl set TotalX = (select sum(X) from DetailTbl where DetailTbl.MasterID = MasterTbl.ID) update MasterTbl set TotalY = (select sum(Y) from DetailTbl where DetailTbl.MasterID...

What's a good tool to run SQL scripts against any database?

Currently I have a custom tool which generates vanilla-SQL (only using standard SQL), from our Data-models that sets up database schemas and initial data for our new databases, and do version patches, etc... This part is all fine and dandy right now. However running these SQL scripts against all the different databases (different vendor...

Updating an associative table in MySQL

Below is my (simplified) schema (in MySQL ver. 5.0.51b) and my strategy for updating it. There has got to be a better way. Inserting a new item requires 4 trips to the database and editing/updating an item takes up to 7! items: itemId, itemName categories: catId, catName map: mapId*, itemId, catId * mapId (varchar) is concat of itemId +...

SQL Server - Query Execution Plan For Conditional Statements

How do conditional statements (like IF ... ELSE) affect the query execution plan in SQL Server (2005 and above)? Can conditional statements cause poor execution plans, and are there any form of conditionals you need to be wary of when considering performance? ** Edited to add ** : I'm specifically referring to the cached query execu...