sql

SSAS - Moving Annual Total

Environment: SQL-Server-2005, SSAS 2005 I am using the following formula to create a Moving Annual Total SUM ({[Time].CurrentMember.Lag(3):[Time].CurrentMember}, [Measures].[TRx Quantity]) The same column [Measures].[Trx Quantity] is used in other calculations and it works fine. This one, however, comes up with #Value! to indicate so...

How can I use if statement after a CTE (SQL Server 2005)

Last night I was writing a simple T-SQL program something like this DECLARE @ROLEID AS INT SELECT @ROLEID = [ROLE ID] FROM TBLROLE ;WITH CTE AS ( SELECT * FROM SOMETABLE ) IF (@ROLEID = 1) BEGIN //SOMECODE END ELSE IF(@ROLEID = 2) BEGIN //SOMECODE END ELSE BEGIN //SOMECODE END I found after compilation th...

ProviderException: InvalidCastException

Few of our clients are regularly getting invalid cast exception, with variations i.e. InvalidCastException / ProviderException, but both generating from method call: System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) The other variation is: Exception type: InvalidCastException Exception message: Unable to cast o...

Oracle length() function returning incorrect value.

I just found some... I don't know what I'd call it but here goes: SELECT part_num, length(trim(part_num)) FROM part_programs WHERE rownum <= 10; ...results: PART_NUM LENGTH(TRIM(PART_NUM)) --------------- ---------------------- THAB256 8 THA1256674 11 THA1256674GU 13 THA1257141 11 THA1257141FR...

Count number of nodes in a level in a nested set

I am using Ruby (Ruby on Rails) and have a nested set of about 2000 nodes. Each node can only have two children. What is the best way to determine how many nodes are in each level? Do I have to crawl the entire tree looking for sibling to do this? Thanks! ...

SQL Server equivalent of Javascript UnEscape

I have a table in SQL Server 2008 with a column having the string stored in JavaScript Escape format. When queried from application, I am doing the JavaScript UnEscape of the returned string, so no issues. How do i UnEscape the string when I directly query the database? Is there any equivalent function for JavaScript UnEscape in SQL? ...

LINQ syntax vs SQL syntax

Why did Andres Heilsberg designed LINQ syntax to be different than that of SQL (whereby made an overhead for the programmers to learn a whole new thing)? Weren't it better if it used same syntax as of SQL? ...

streamlining creating of packages and views

I have few SQL scripts which setups the db of an app. have few scripts creating packages which has few references of views, and similarly have scripts for creating views which has references of packages. Is there a way to separate these two scripts which would then individually create only packages or views respectively. Or any alterna...

How can I query from two tables but get results only from one?

I have list of contacts and then I have list of blocked contacts. I need to query contacts that are not blocked. How can I make query where all blocked contacts are filtered out inside the sql query? ...

List stored functions using a table in PostgreSQL

Just a quick and simple question: in PostgreSQL, how do you list the names of all stored functions/stored procedures using a table using just a SELECT statement, if possible? If a simple SELECT is insufficient, I can make do with a stored function. My question, I think, is somewhat similar to this other question, but this other question...

jquery: adding value from appended elements to the database

Greetings, I got the following problem: By clicking on the button "Add Flavor" (see full sample code), a dropdown-box, text field and two checkboxes are dynamically generated, - each time the click on the button is performed. Is there a way to add the values from the dynamically generated (actually "appended") elements to the database...

[SQL] How do I group by month and year when only having a datetime field?

I have a table schema which is essentially a bunch of transaction info with a datetime field TRANSACTION (< transactionid >, amount, when) I need to generate a monthly total of transactions, which is SUM(amount), but I stumped by what do I group by. Each row from SQL should contain the monthly total (so one row for Jan 09, Feb 09....J...

DECODE( ) function in SQL Server

SELECT PC_COMP_CODE, 'R', PC_RESUB_REF, DECODE(PC_SL_LDGR_CODE,'02','DR','CR'), PC_DEPT_NO DEPT, '',--PC_DEPT_NO, PC_SL_LDGR_CODE+'/'+PC_SL_ACNO, SUM( DECODE(PC_SL_LDGR_CODE,'02',1,-1) *PC_AMOUNT), PC_CHEQUE_NO CHQNO FROM GLAS_PDC_CHEQUES WHERE PC_RESUB_REF IS NOT NULL AND PC_DISCD NOT IN ('d','D','T') GROUP BY PC_RES...

Combining Java with SQL?

This isn't a code question for once, but it definitely has me confused. Basically, my lecturer has told me that we have a project due next semester that involves us to use Java and SQL intertwined with each other. I had no idea the combining of languages was even possible! So my mind's really blown. I've been searching around looking...

SQL join on many queries

Hi, I have a table with a structure such as table(PK, a, b, c, d, e, f, g). And I have many queries that I want to join: select PK, sum(c) where... JOIN select PK, sum(e) where... JOIN select PK, sum(g) where ... JOIN select PK,a,b,d,f Every sum(c|e|g) is actually a select sum(c|e|g) from .... where... because there are m...

How to send request from client side if one table affects

I am inserting a row in one table say appcapacity using stored procedure at every 1 min using timer task in java. I am monitoring that table in admin side as chart with two column values say (TIME,FILESIZE) as x and y respectively. ie. in client side by using Google visualization API. table : appcapacity TIME FILESIZ...

How to join results from two tables in Oracle 10

Let say that I have 2 tables with the same structure : STOCK and NEW_STOCK. These tables have a primary key composed of (ID_DATE, ID_SELLER, ID_INVOICE, ID_DOC). Now, I need to get for every (ID_DATE, ID_SELLER, ID_INVOICE, ID_DOC), the value of the amount (field AMOUNT) regarding this requirement: If a record is present in NEW_STOCK, ...

What is db/development_structure.sql in a rails project?

There is a development_structure.sql inside my /db folder of my rails application (rails 2.3.4, ruby 1.8.7) and I am not sure exactly what it does. Is it needed for some specific environment? (I think I read somewhere that it's used for tests) Do I need to add it to my git repository? ...

php dynamic checkboxes

Currently I have a form that submits an image with textfields such as title, description and another field that autoincrements for imageID, another area for the actual file , called vfile, and *** another part that has 3 checkboxes and a text field. Everything works fine, and this is what it does. Submits the data to a database so that i...

Autocommit vs. Single Transactions (Small Project vs. Big Project)

Hi there, I am currently working on a very specialized PHP framework, which might have to handle large database transfers. For example: Take half of the whole user count; this should be every day's workspace for the framework. So, if my framework is required by big projects, is it recommend to use single transactions with multiple qu...