I am new to SQL SERVER and need your advise on something. I have a big table with stores information. Here is bench_id column: **bench_id** 31 51 51 61 61 61 71 71 I have created another small table …
Tag: sql
MySQL INSERT INTO … VALUES and SELECT
Is there a way to insert pre-set values and values I get from a select-query? For example: I have the value of “A string” and the number 5, but I’ve to find the [int] value from a select like this: that gives me that id to put inside table1. How to merge this into one statement? Answer Use a…
How can I temporarily disable a foreign key constraint in MySQL?
Is it possible to temporarily disable constraints in MySQL? I have two Django models, each with a foreign key to the other one. Deleting instances of a model returns an error because of the foreign key constraint: Is it possible to temporarily disable constraints and delete anyway? Answer Try DISABLE KEYS or …
mysql change all values in a column
I want to change all values in the tablecolumn “Quellendatum”. When the row-value is 2005-06-20 then it should be replaced with 2012-06-20. When the row-value is NULL or empty, then it should be …
SQL Server – Create a copy of a database table and place it in the same database?
I have a table ABC in a database DB. I want to create copies of ABC with names ABC_1, ABC_2, ABC_3 in the same DB. How can I do that using either Management Studio (preferably) or SQL queries ? This is for SQL Server 2008 R2. Answer Use SELECT … INTO: This will create a new table ABC_1 that has
Pivot on Multiple Columns using Tablefunc
Has anyone used tablefunc to pivot on multiple variables as opposed to only using row name? The documentation notes: The “extra” columns are expected to be the same for all rows with the same row_name value. I’m not sure how to do this without combining the columns that I want to pivot on (w…
Using ISNULL when adding NULL to varchar
Whilst experimenting with MSSQL I came across some behaviour I cannot explain. I was looking at what happens to a NULL value when it is added to a varchar, and when I do the following query: I get the result ‘te’. Similarly if I change the word test for any other word I only get the first two lett…
Updating a Table after some values are inserted into it in SQL Server 2008
I am trying to write a stored procedure in SQL Server 2008 which updates a table after some values are inserted into the table. My stored procedure takes the values from a DMV and stores them in a table. In the same procedure after insert query, I have written an update query for the same table. Insert result…
How to convert a loop in SQL to Set-based logic
I have spent a good portion of today and yesterday attempting to decide whether to utilize a loop or cursor in SQL or to figure out how to use set based logic to solve the problem. I am not new to set logic, but this problem seems to be particularly complex. The Problem The idea is that if I have
How can I connect C# with Db with App.config?
I need to connect C# with SQL Server database using app.config. My code is: and in app.config I have: but I get an error and I can’t fix it: ConfigurationErrorExeption was Unhandled Configuration system failed to initialize Can anyone help me please ? Answer Try: You’re referencing Conn as the con…