Skip to content
Code Project
CODE PROJECT For Those Who Code

Database

Discussions on database access, SQL, and ADO

This category can be followed from the open social web via the handle database@forum.codeproject.com

17.1k Topics 61.8k Posts
  • How to cut space in middle word

    database help tutorial question
    3
    0 Votes
    3 Posts
    0 Views
    L
    now i reach my result..thanks alot
  • 0 Votes
    4 Posts
    0 Views
    N
    Try this declare @tbl table(SomeField varchar(50)) insert into @tbl(SomeField) values('Bob''s') select * from @tbl Output: SomeField Bob's Instead of 'Bob's' write 'Bob'**'**s'. Hope this helps :) Niladri Biswas
  • Invalid argument in a DateDiff() function

    help database
    9
    0 Votes
    9 Posts
    0 Views
    T
    I figured it out. The contacted the company who produced the connector. It does not support a DateDiff() function :-/ I also contacted the third party vender and they stated that they have a built in function for it. Hopefully that works. Thanks a lot for your time and help! Jude
  • Microsoft Sql Server and the Decimal Data Type

    database sql-server sysadmin
    8
    0 Votes
    8 Posts
    0 Views
    L
    AFAIK decimal(4,2) can hold the range (-99.99,+99.99), and not 123.4 :) Luc Pattyn I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
  • What would be the equivalent in SQL??

    database question sql-server tutorial
    4
    0 Votes
    4 Posts
    0 Views
    T
    Thanx a bunch! Jude
  • 0 Votes
    4 Posts
    0 Views
    L
    Just add the IDENTITY column, SQL Server will fill the values automatically.
  • horizontal union operation

    database com tutorial question
    7
    0 Votes
    7 Posts
    0 Views
    L
    Add a new AutoNumber column to both these tables and use it to join the tables.
  • select @@basedir

    mysql question
    1
    0 Votes
    1 Posts
    0 Views
    No one has replied
  • Weighted average in T-SQL (like Excel's SUMPRODUCT)

    database
    3
    0 Votes
    3 Posts
    0 Views
    N
    If I have understand your requirement, then try this SET DATEFORMAT dmy declare @tbl table(A int, B int,recorddate datetime,KPI varchar(50)) insert into @tbl select 1,10 ,'21/01/2009', 'Weighty'union all select 2,20,'10/01/2009', 'Tons Milled' union all select 3,30 ,'03/02/2009', 'xyz'union all select 4,40 ,'10/01/2009', 'Weighty'union all select 5,50 ,'05/01/2009', 'Tons Milled'union all select 6,60,'04/01/2009', 'abc' union all select 7,70 ,'05/01/2009', 'Weighty'union all select 8,80,'09/01/2009', 'xyz' union all select 9,90 ,'05/01/2009', 'kws' union all select 10,100,'05/01/2009', 'Tons Milled' select SUM(t1.A*t2.A)/SUM(t2.A)Result from (select RecordDate,A,B,KPI from @tbl)t1 inner join(select RecordDate,A,B,KPI from @tbl t)t2 on t1.RecordDate = t2.RecordDate and t1.KPI = t2.KPI Hope this helps :) Niladri Biswas modified on Monday, November 9, 2009 12:00 AM
  • Sql server license key

    question csharp database sql-server visual-studio
    2
    0 Votes
    2 Posts
    0 Views
    A
    prathapcode wrote: And now coming to SQL server whether licensed key is required? AFAIK sql server express can be freely distributed. Just you need to create a setup application and execute its installer from your program. :) Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution. My Latest Articles-->** Simplify Code Using NDepend Basics of Bing Search API using .NET Microsoft Bing MAP using Javascript
  • backp updated row

    database question oracle announcement
    2
    0 Votes
    2 Posts
    0 Views
    A
    use Update Trigger. Whenever the row is updated use :old and :new objects to get the data from updated row and new row. If it is after update trigger, you need to use :old to get old values otherwise use select from table to get the value. Now insert them to the log table. For instance : CREATE OR REPLACE TRIGGER orders\_after\_update AFTER UPDATE ON orders FOR EACH ROW DECLARE v\_username varchar2(10); BEGIN -- Find username of person performing UPDATE into table SELECT user INTO v\_username FROM dual; -- Insert record into audit table INSERT INTO orders\_audit ( order\_id, quantity\_before, quantity\_after, username ) VALUES ( :new.order\_id, :old.quantity, :new.quantity, v\_username ); END; :) Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution. My Latest Articles-->** Simplify Code Using NDepend Basics of Bing Search API using .NET Microsoft Bing MAP using Javascript
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • 0 Votes
    4 Posts
    0 Views
    M
    When setting up the linked server you have not applied the correct credentials. When, under duress, we need to do this we use a SQL standard account between servers and set it up in SSMS when creating the linked server. Never underestimate the power of human stupidity RAH
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • Help Creating a Temp Table

    database help
    4
    0 Votes
    4 Posts
    0 Views
    N
    ;with cte as(select t1.*, t2.* from table1 t1 cross join table2 t2) select * from cte OR ;with cte as(select t1.*, t2.* from table1 t1 ,table2 t2) select * from cte :) Niladri Biswas
  • Using OPENROWSET

    database help
    2
    0 Votes
    2 Posts
    0 Views
    J
    I would suggest you take a look at the example given at http://syntaxhelp.com/SQLServer/OPENROWSET/CSV[^]
  • Mysql

    database mysql
    2
    0 Votes
    2 Posts
    0 Views
    N
    Hi Jayabharati, I am sorry but I am a SQL SERVER guy. Henceforth I am not able to write the query for you. But you can find your answer form here(Exactly the same question you are looking for.. I believe) http://stackoverflow.com/questions/1384245/way-to-search-entire-database-for-a-string-in-mysql[^] Hope this helps. :) Niladri Biswas
  • How to update multiple rows in a table.

    database help tutorial announcement
    5
    0 Votes
    5 Posts
    0 Views
    N
    Hi, Update the target table based on bug date Here is the example Just creating a dummy source table declare @tblSource table(bugdate datetime) insert into @tblSource select '2009-04-12' union all select '2009-04-19' union all select '2009-04-26' union all select '2009-05-03' union all select '2009-05-10' union all select '2009-05-17' union all select '2009-05-24' union all select '2009-05-31' union all select ' 2009-06-07' Your target table schema create table tblTarget (id int,bugdate date,weekno int,bugno int,startdayofweek datetime) insert into tblTarget select 111,'2009-04-12',null,3,null union all select 111,'2009-04-19',null,1,null union all select 111,'2009-04-26',null,1,null union all select 111,'2009-05-03',null,1,null union all select 111,'2009-05-10',null,9,null union all select 111,'2009-05-17',null,9,null union all select 111,'2009-05-24',null,4,null union all select 111,'2009-05-31',null,2,null union all select 111,' 2009-06-07',null,4,null select * from tblTarget Output (Before updation) id bugdate weekno bugno startdayofweek 111 2009-04-12 NULL 3 NULL 111 2009-04-19 NULL 1 NULL 111 2009-04-26 NULL 1 NULL 111 2009-05-03 NULL 1 NULL 111 2009-05-10 NULL 9 NULL 111 2009-05-17 NULL 9 NULL 111 2009-05-24 NULL 4 NULL 111 2009-05-31 NULL 2 NULL 111 2009-06-07 NULL 4 NULL Next execute the query ;with cte as ( select bugdate, DATEADD(wk, DATEDIFF(wk, 6,bugdate), 6) as startdayofweek, Datepart(wk,bugdate) + ((Datepart(year,bugdate) - 2008) * 52) as WeekNumber from @tblSource ) update tblTarget set tblTarget.weekno = c.WeekNumber,tblTarget.startdayofweek = c.startdayofweek from cte c where c.bugdate = tblTarget.bugdate Output(After Updation) id bugdate weekno bugno startdayofweek 111 2009-04-12 68 3 2009-04-12 00:00:00.000 111 2009-04-19 69 1 2009-04-19 00:00:00.000 111 2009-04-26 70 1 2009-04-26 00:00:00.000 111 2009-05-03 71 1 2009-05-03 00:00:00.000 111 2009-05-10 72 9 2009-05-10 00:00:00.000 111 2009-05-17 73 9 2009-05-17 00:00:00.000 111 2009-05-24 74 4 2009-
  • 0 Votes
    7 Posts
    0 Views
    S
    Dave Thanks for the help. My solution is as follows :- SELECT NULL as TicketId, *, NULL as Quantity FROM vuDepotProducts WHERE NOT EXISTS( SELECT * FROM vuReceipts WHERE DepotId = vuDepotProducts.DepotId AND ProductId = vuDepotProducts.ProductId AND TicketId = 330804 ) UNION SELECT * FROM vuReceipts WHERE vuReceipts.TicketId = 330804 Steve Jowett ------------------------- Real programmers don't comment their code. If it was hard to write, it should be hard to read.
  • 0 Votes
    3 Posts
    0 Views
    L
    This question has been answered in the C# forum. Please don't post more than once.