Skip to content

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
  • Error trapping in SQL Server 2005 [modified]

    database sql-server sysadmin help
    7
    0 Votes
    7 Posts
    0 Views
    J
    SQL server has try/catch. But you need to be careful with it. One might think that they could put that in every proc as thus record errors but I am rather certain that in many procs the errors that might occur would be the ones that would be compounded by attempting another write to the database. For example a table space error.
  • Stored Procedure to find emails

    database sharepoint algorithms sales
    6
    0 Votes
    6 Posts
    0 Views
    L
    A little change makes it work. Just add a CustomerType column to the Priority table and include the CustomerType in the WHERE clause.
  • Dynamic sort

    help database question
    7
    0 Votes
    7 Posts
    0 Views
    J
    Seems to be some confusion in the back and forth in the answers above. A SQL text literal is expressed like the following example. 'abc' If you want to embed a single tick in the above literal you MUST escape it. The standard SQL (ANSI) idiom for that is as follows (but some databases offer other ways.) 'a''bc' So two single ticks become one. Three ticks is NEVER correct.
  • 0 Votes
    3 Posts
    8 Views
    H
    I miss the Command.Connection.Open() before you executeNonQuery() In Word you can only store 2 bytes. That is why I use Writer.
  • 0 Votes
    4 Posts
    0 Views
    M
    I think the problem is with your connection string. Follow the link find your desired one. http://www.connectionstrings.com/[^] Enjoy :)
  • 0 Votes
    39 Posts
    0 Views
    P
    jschell wrote: you quoted a specific statement and then said it was wrong. jschell wrote: One problem with guids is that they have no implicit ordering This is 100% incorrect I took it that he disagreed with the "One problem with" part of the statement, as do I. The "guids ... have no implicit ordering" is correct, but it is a benefit, not a problem.
  • Last record in MYSQL

    mysql tutorial question announcement
    3
    0 Votes
    3 Posts
    0 Views
    T
    If you have auto increment column in your table then you may use LAST_INSERT_ID()[^] thatraja **My Tip/Tricks My Dad had a Heart Attack on this day so don't... **
  • Count Left Nodes

    2
    0 Votes
    2 Posts
    0 Views
    U
    Yes I have same table and want sql query for counting left and right node
  • 0 Votes
    1 Posts
    0 Views
    No one has replied
  • Find Last Record In Sequence

    database sql-server sysadmin tutorial question
    10
    0 Votes
    10 Posts
    0 Views
    A
    For anyone who is interested, here is my solution: SELECT Orders.ExampleData FROM OrderSeq AS Orders LEFT JOIN OrderSeq AS Updates ON (Orders.OrderId = Updates.OldOrderId) AND (Updates.[Type] = 'U') where (Updates.RowId IS NULL) I knew it was easy, just couldn't get my head around it this morning. Thanks to everyone who replied.
  • 0 Votes
    22 Posts
    3 Views
    _
    Mycroft Holmes wrote: possibly we have simpler deployments Heh :) We have quite complex deployment issues right now indeed. We're maintaining a lot of branches for our customers. And it's not always as easy as it's supposed to be when the time has come to merge all the stuff together after a long period of time.
  • How to do a select statement from two or more tables?

    help tutorial question
    5
    0 Votes
    5 Posts
    0 Views
    N
    Declare @Student table(StudentID int identity,Name varchar(20)) Declare @Poke table(Poke_Id int identity,Poke_Giver_Id int,Poke_Receiver_Id int) insert into @Student values('Alex'),('Bob'),('Caveman') insert into @Poke values(1,2),(1,2),(2,1) Select x.Poke_Id,x.Poke_Giver_Name,Poke_Receiver_Name = s.Name from( Select p.Poke_Id,s.Name Poke_Giver_Name ,p.Poke_Receiver_Id from @Poke p join @Student s on p.Poke_Giver_Id = s.StudentID )x join @Student s on s.StudentID =x.Poke_Receiver_Id /* Poke_Id Poke_Giver_Name Poke_Receiver_Name 1 Alex Bob 2 Alex Bob 3 Bob Alex */ Niladri Biswas
  • 0 Votes
    7 Posts
    0 Views
    L
    You cannot set password on the SQL Server mdf file as you do with an Access mdb file. Use SQL Server Authentication to restrict what users can see.
  • 0 Votes
    2 Posts
    0 Views
    P
    Replying to my own message. My good colleague Adam found an excellent blog post about this exact problem. The solution to this problem is simple is to edit the your model edmx file. In the property element which originaly was: I need to add the StoreGeneratedPattern="Identity" attribute. The generated SQL then seems very good, as not only the default value are not overwritten but they are returned to the client in a single query. declare @generated_keys table(ContactGUID uniqueidentifier) insert [dbo].[dtblContact](surname, forname) output inserted.ContactGUID into @generated_keys values ('Blog', 'Joe') select t.ContactGUID from @generated_keys as g join [dbo].dtblContact as t on g.ContactGUID = t.ContactGUID where @@ROWCOUNT > 0 For more details visit: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/[^] modified on Friday, July 22, 2011 4:39 AM
  • :-\ Select

    6
    0 Votes
    6 Posts
    0 Views
    P
    velmahesh wrote: Please,Dont Forget to click   Accept Answer and Click vote.. Earn Points. That's an automatic 1.
  • SSRS 2005 Sub report issue (newbie)

    database sql-server help question
    2
    0 Votes
    2 Posts
    0 Views
    P
    I've just found out (by accident) that sub-reports in my version of BID do not preview - Once deployed they show up fine.
  • 0 Votes
    13 Posts
    0 Views
    L
    Wow, it's been almost 3 years since this thread was started and the answer is still helpfull :-D
  • Calculate and display a progressive balance

    database question
    5
    0 Votes
    5 Posts
    0 Views
    S
    Yes. (BTW, this is not really a beginner's task you are attempting in case you are wondering.) Yes, but life gets easier if you have a row number of some kind. As your example shows there's no particular order to these entries; they all have the same date. There is nothing indicating which ones you want first. I've added single quotes to your example entries. If you added another column to indicate order you could have this query: Declare @Table Table ( row int, EmployeeName Varchar(50),joiningDate DateTime, Amount int,Balance int ) insert into @Table Select 1, 'Abc','07/03/2010',6000,0 UNION ALL Select 2, 'xyz', '07/03/2011',1500,0 UNION ALL Select 3, 'Rameez', '07/03/2011',2000,0 UNION All Select 4, 'Abhijit', '07/03/2011',1000,0; --UNION ALL select xx.* ,(select sum(Amount) from @Table xy where xy.row <=xx.row ) RunningTotal from @Table xx As you can see the number inserted with the information is working just fine. This next version uses an identity column in the table to do the same job so if you have a lot of entries you won't have to pre-set all of their numbers. Declare @Table Table ( row int identity(1,1), EmployeeName Varchar(50),joiningDate DateTime, Amount int,Balance int ) insert into @Table ( EmployeeName ,joiningDate ,Amount ,Balance ) Select 'Abc','07/03/2010',6000,0 UNION ALL Select 'xyz', '07/03/2011',1500,0 UNION ALL Select 'Rameez', '07/03/2011',2000,0 UNION All Select 'Abhijit', '07/03/2011',1000,0; --UNION ALL select xx.* ,(select sum(Amount) from @Table xy where xy.row <=xx.row ) RunningTotal from @Table xx In this last example you can see I'm using row_number() to artificially create a row number on the fly. Declare @Table Table ( EmployeeName Varchar(50),joiningDate DateTime, Amount int,Balance int ) insert into @Table Select 'Abc','07/03/2010',6000,0 UNION ALL Select 'xyz', '07/03/2011',1500,0 UNION ALL Select 'Rameez', '07/03/2011',2000,0 UNION All Select 'Abhijit', '07/03/2011',1000,0; with CTE01 as (select * ,ROW_NUMBER() over (order by joiningdate) row from @Table ) select xx.* ,(select sum(Amount) from CTE01 xy where xy.row <= xx.row ) RunningTotal from CTE01 xx I went ahead and used a common table expression (CTE) here because row_number can be a little intransigent when you use it directly in the subquery, but it works just fine in the CTE. Hopefully this all makes enough sense that you can co
  • SQL Syntax Issue

    database help sql-server sysadmin
    3
    0 Votes
    3 Posts
    0 Views
    L
    Member 8003276 wrote: ADD PRIMARY KEY (BatchID,StartTime) Try: ALTER TABLE BatchData ADD CONSTRAINT PK_BatchData PRIMARY KEY (BatchID, StartTime); It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca
  • UPDATE Multiple tables on one filed. [modified]

    tools tutorial announcement
    5
    0 Votes
    5 Posts
    0 Views
    N
    Hi, I am providing a solution to this problem but ideally you should follow as what Shameel has said.. Let us create 4 tables (one master and three child tables) as under CREATE TABLE [dbo].[tblmaster]( [testID] [varchar](50) NULL, [Name] [varchar](50) NULL ) ON [PRIMARY] CREATE TABLE [dbo].[tblChild1]( [testID] [varchar](50) NULL, [Name] [varchar](50) NULL, [Age] [int] NULL ) ON [PRIMARY] CREATE TABLE [dbo].[tblChild2]( [testID] [varchar](50) NULL, [Name] [varchar](50) NULL, [Address] [varchar](50) NULL ) ON [PRIMARY] CREATE TABLE [dbo].[tblChild3]( [testID] [varchar](50) NULL, [Sex] [varchar](6) NULL, [Address] [varchar](50) NULL, [Phone Number] [varchar](50) NULL ) ON [PRIMARY] insert into tblmaster select 's401', 'name10' union all select 's402', 'name11' union all select 's403', 'name12' union all select 's404', 'name14' insert into tblChild1 select 's401', 'name20', 20 union all select 's402', 'name21', 21 union all select 's403', 'name22', 22 union all select 's404', 'name23',23 insert into tblChild2 select 's401', 'name30', 'address30' union all select 's402', 'name31', 'address31' union all select 's403', 'name32', 'address32' union all select 's404', 'name33', 'address33' insert into tblChild3 select 's401', 'male', 'address40','9885446789' union all select 's402', 'female', 'address41','12345678' union all select 's403', 'male', 'address42','34567891' union all select 's404', 'female', 'address43','0986234' Select * from tblmaster Select * from tblChild1 Select * from tblChild2 Select * from tblChild3 Now fire the below query exec sp_msforeachtable N' IF EXISTS(SELECT 1 FROM sys.columns WHERE object_id=OBJECT_ID(''?'') AND name = ''testID'') EXEC (''UPDATE ? SET testID= case when testID = ''''s401'''' then ''''I00010'''' when testID = ''''s402'''' then ''''I00020'''' when testID = ''''s403'''' then ''''I00030'''' when testID = ''''s404'''' then ''''I00040'''' end'')' N.B.~ Use this example as a reference for your problem. Thanks Niladri Biswas modified on Tuesday, July 19, 2011 5:48 AM