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
  • 0 Votes
    6 Posts
    0 Views
    L
    It is very difficult to guess what is going on without more information about the actual code that causes the exception. Please show the code where the error occurs, indicating the exact line that raises the exception, and the exact content of all variables that are being used.
  • 0 Votes
    2 Posts
    0 Views
    L
    Most unlikely no. How would you encrypt something like "ihaveaverylongnameincludingahyphen@mylogsurname.microsoft.com", without losing some characters?
  • 0 Votes
    7 Posts
    0 Views
    M
    I do believe he is giving customers table and alias of destination_table, apparently MySQL allows aliasing in an update. This was my first reaction as well. Never underestimate the power of human stupidity RAH
  • Restore CDC Data

    help database sales tools question
    2
    0 Votes
    2 Posts
    0 Views
    M
    I found the solution, may be useful to someone, I should update the start_lsn field in the change_tables to map to first entry in the CDC table. This table is queried by most of the system-defined procs/functions, hence this needs to be updated with the accurate start_lsn: UPDATE cdc.change_tables SET start_lsn = (SELECT MIN(__$start_lsn) FROM cdc.dbo_MyTable_CDC) WHERE capture_instance = 'dbo_MYTable';
  • Data duplication on multiple fields

    4
    0 Votes
    4 Posts
    0 Views
    J
    What RDBMS are you using? You could do something like SELECT DISTINCT (your 7 columns) FROM table to get the unique values if that's what you're looking for.
  • movement of foreign key

    question
    2
    0 Votes
    2 Posts
    0 Views
    L
    From what you show only the following can be done/makes sense: products ( .... CONSTRAINT FK_products_cat FOREIGN KEY (product_cat) REFERENCES product_Category(cat_id) ) You need to think again about the layout. It seems that products needs something like product_Brand instead of product_cat_brand. In case this assumption is right then: products ( .... CONSTRAINT FK_products_cat FOREIGN KEY (product_cat) REFERENCES product_Category(cat_id) CONSTRAINT FK_products_brand FOREIGN KEY (product_brand) REFERENCES product_Brand(brand_id) )
  • Error: Conversion failed when converting the varchar value

    10
    0 Votes
    10 Posts
    8 Views
    M
    Our naming conventions are similar, code and id are very different types ;P Never underestimate the power of human stupidity RAH
  • sql linq, data duplication on 1 particular record

    2
    0 Votes
    2 Posts
    0 Views
    J
    I forgot about joining a table that has multiple records that match, which creates multiple primary records, so you have to group. Anyways, I did this for the time being, don't know why I didn't think of it yesterday. I keep thinking that I didn't know the value of d.departmentID in order to make a match. pResults = ( from d in context.PRODUCT_DEPARTMENT join da1 in context.PRODUCT_DEPARTMENT_AVATARS on d.Avatar_Primary equals da1.AvatarID into avatars from da1 in avatars.DefaultIfEmpty() where d.Deleted == false orderby d.Name select new model_departments_index { DepartmentID = d.DepartmentID, Enabled = d.Enabled, Deleted = d.Deleted, Name = d.Name, Description = d.Description, Featured = d.Featured, Rollback = d.Rollback, Avatar_Primary_ID = d.Avatar_Primary, Avatar_Primary_Image = new model_type_avatar { Name = da1.Name, Alt = da1.Alt, Data = da1.Data, Type = da1.Type, Url = da1.Url }, Categories = ( from c in context.PRODUCT_CATEGORY where c.DepartmentID == d.DepartmentID select new json_product_categories { text = c.Name, value = c.CategoryID } ).ToList() } ).ToList(); pValue = pResults.Count();
  • Time calculation

    5
    0 Votes
    5 Posts
    0 Views
    A
    Thanks.. I got the answer
  • SQL Transactions - Torn apart in old code

    5
    0 Votes
    5 Posts
    0 Views
    H
    THANKS! I now reread it and got it. Maybe that was the knot in my head! X| Rules for the FOSW ![^] if(this.signature != "") { MessageBox.Show("This is my signature: " + Environment.NewLine + signature); } else { MessageBox.Show("404-Signature not found"); }
  • How to Search for names in MySQL

    2
    0 Votes
    2 Posts
    0 Views
    M
    I don't know about MySQL but in SQL Server I have done the following in the past. Build a function that takes a string and splits it on a delimiter (space) and return a table. In your query left outer join the function, passing in your name field, on your name field with Name = or LIKE '%' + itemFromFunction + '%' Make the result set DISTINCT. Not sure if = or like is needed in the LOJ. This is an old SQL Server split function I dug up. ALTER FUNCTION [dbo].[fn_Split] (@List varchar(8000), @Delimiter char(1)) RETURNS @Results table (Item varchar(8000),ID int Identity(1,1)) AS begin declare @IndexStart int declare @IndexEnd int declare @Length int declare @Word varchar(8000) set @IndexStart = 1 set @IndexEnd = 0 set @Length = len(@List) If @Delimiter = '' Set @Delimiter = ',' --Get rid of any tabs or returns Set @List = Replace(@List,char(9),'') Set @List = Replace(@List,char(10),'') Set @List = Replace(@List,char(13),'') while @IndexStart <= @Length begin set @IndexEnd = charindex(@Delimiter, @List, @IndexStart) If @Delimiter = char(32) set @IndexEnd = charindex(Space(1), @List, @IndexStart) if @IndexEnd = 0 set @IndexEnd = @Length + 1 set @Word = substring(@List, @IndexStart, @IndexEnd - @IndexStart) set @IndexStart = @IndexEnd + 1 INSERT INTO @Results(Item) SELECT @Word end return end Never underestimate the power of human stupidity RAH
  • Need guidance: duplicate oracle db to another

    7
    0 Votes
    7 Posts
    0 Views
    J
    No, you can choose whether you want to export schemas, tablespaces, tables or the whole database. Data Pump Export[^] Wrong is evil and must be defeated. - Jeff Ello
  • Prioritized joining - Updated

    11
    0 Votes
    11 Posts
    0 Views
    J
    The data turned out to be a lot less ordered or rather more asymmetrical than expected (just like I should've expected :rolleyes:) And the mapping between the databases also turned out to be important in only one direction. So I ended up using a variant of your solution, but using RANK instead of ROW_NUMBER. Now I'm working on refining the ranking function for whenever I get duplicate matches Wrong is evil and must be defeated. - Jeff Ello
  • DB backup initiated by NT AUTHORITY\SYSTEM

    2
    0 Votes
    2 Posts
    0 Views
    Richard DeemingR
    And this is yet another copy of the same re-posted question from the thread below. Database backed up type virtual device- not mainteance job[^] Database backed up type virtual device- not mainteance ? - Database Discussion Boards[^] Database backed up type virtual device- not mainteance job - Database Discussion Boards[^] "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • Database backed up type virtual device- not mainteance job

    2
    0 Votes
    2 Posts
    0 Views
    Richard DeemingR
    You have already asked this question, and been given the answer: Database backed up type virtual device- not mainteance ? - Database Discussion Boards[^] The answer hasn't changed in the last three weeks. "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • call sql scripts from others folders

    7
    0 Votes
    7 Posts
    0 Views
    CHill60C
    You can use the sqlcmd utility from a windows batch file e.g. @ECHO OFF FOR /F %%i IN ('sqlcmd -S YourDBInstance -Q"set nocount on;select CONVERT(DECIMAL(10,2),FVersion) from TVersion"') DO SET VNO=%%i call .\v%VNO%\script.bat @echo done. Things to note - you'll have to insert your own information for the -S parameter - Do not put spaces around the = sign in SET VNO=%%i - The conversion in the query is necessary to ensure the .00 is returned correctly - you will need to substitute your script name for script.bat
  • Pivot Not Working

    8
    0 Votes
    8 Posts
    0 Views
    M
    Psst! Enhance his rep by upvoting his response, green angle on the left! Never underestimate the power of human stupidity RAH
  • 0 Votes
    2 Posts
    0 Views
    Richard DeemingR
    When you take a backup of your disk, you can't just take a copy of the SQL database files. If you did, you could end up with an unusable backup. Instead, the backup product uses the Volume Shadow Copy Service to communicate with SQL Server. SQL then initiates a proper backup of the databases, writing them out to a virtual device that represents the target of the backup job. This is perfectly normal, and nothing to worry about. "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
  • syntax error for simple IF - THEN

    help mysql com announcement
    5
    0 Votes
    5 Posts
    0 Views
    T
    You didn't get Peter's reply which's fair enough? Just remove EXISTS from that query & run. It's over. thatraja Coming soon1 | Coming soon2 | Coming soon3New
  • Call dll from SQL trigger

    database help csharp sql-server
    4
    0 Votes
    4 Posts
    0 Views
    Richard DeemingR
    So you need to make the function static / Shared: Public Class Class1 Public Shared Function abc(ByVal a As String) As String Return a.ToUpper End Function End Class NB: The function you've shown will not work as a trigger. A SQL CLR trigger needs to be a Sub which uses the SqlContext.TriggerContext to perform its work. CLR Triggers[^] How to: Create and Run a SQL Server Trigger by using Common Language Run-time Integration[^] Detailed SQL Server data audit through a .NET (CLR) trigger[^] "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer