Click here to Skip to main content
15,892,737 members
Everything / Programming Languages / SQL

SQL

SQL

Great Reads

by Alex Pumpet
A simple program for comparing table data from two sources - SQL databases, Excel, CSV or XML-files
by Thomas Weller
Demonstrates how to run Python scripts from C#
by Mubin M. Shaikh
Create time dimension with 24 hour plus values and time buckets in your data warehouse
by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).

Latest Articles

by Mishael Ogo
A look at a simple SQL builder for Dapper
by GabrieleTronchin
In this project, I've implemented the Transactional Outbox Pattern using EF Core.
by GabrieleTronchin
A simple stored procedure to add at your database to keep it reactive
by GabrieleTronchin
Automatic creation of non clustered indexes using system SQL entities

All Articles

Sort by Updated

SQL 

18 Apr 2010 by #Jet
i am trying to generate a dynamic where clause in my store proc.=== @population nvarchar(max)declare @chvSelect varchar(max), @chvFrom varchar(max), @chvWhere varchar(max), @chvOrderby varchar(max), @chvSQL...
8 Jan 2010 by #realJSOP
The first thing I would do is evaluate the string in the debugger BEFORE it's sent to your stored procedure. At that point, you can paste it into SQL Manager Express and try the query there to see WHERE your problem is.
28 Jan 2010 by #realJSOP
This is a pretty non-specific question, so you're going to get a non-specific answer. Assumtions:0) You know either the starting date or ending date of the range1) You know how long the range is2) You're not worried about the time componentDateTime start = new...
30 Jan 2010 by #realJSOP
You know, your coding would go A LOT faster if you used google:http://msdn.microsoft.com/en-us/library/ms186724.aspx[^]
4 Feb 2010 by #realJSOP
You can send the xml directly to stored procedure and let the stored procedure deserialize it into the appropriate table(s).Regarding using xml in sql, google is your friend.
25 Apr 2010 by #realJSOP
You have to convert the image into an array of bytes and pass it to your database that way. When you retrieve the image, it will come over as an array of bytes that you then have to convert back to an image.There are plenty of examples if you google it.
1 May 2010 by #realJSOP
You could pass the two dates in question as parameters to a stored procedure, and then write an unencumbered stored proc.
5 May 2010 by #realJSOP
Did you grant permission for the account on the other database? You have to do it for each database you want to run the stored proc on...
24 May 2010 by #realJSOP
Send an email. I personally hate popup messages because you usually have to dismiss them before doing anything else.
24 May 2010 by #realJSOP
Yes, you can call a stored procedure from any .Net app that has the correct references added to it.Specifically, you need to look up the SqlConnection, SqlCommand, and SqlParameter classes. Google is your friend.
1 Jun 2010 by #realJSOP
Heres the query:string query = string.Format("SELECT id from table where id = {0}", myID);
9 Jun 2010 by #realJSOP
Three days after what? Installation? First use?I wouldn't use a DLL, I'd just add code to the application that uses a setting in the app.config file. The first time the app is run, store the date there. Each time the application is run, check the data and compare it to today's date. If the...
25 Jul 2010 by #realJSOP
The unique ID merely identifies the record. Your assumption that one song can only be attributed to a single artist is flawed because many artists might cover the same song. For instance, I know of at least a dozen versions of the title Ghost Riders In The Sky, and some of those versions are...
3 Aug 2010 by #realJSOP
Instead of dealing with complex types, I have a single method in my web services that accepts a stored proc name and a xmlstring of parameters. The web service method translates the xml parameters into sql parameters, and calls the stored proc, which then returns its datasat as xml.One type...
23 Aug 2010 by #realJSOP
Well, once you retrieve the data, it resides in a DataTable, correct? So just use LINQ to query the DataTable object.
26 Aug 2010 by #realJSOP
You can get a much more complete answer by using google to find the answer. If you google this phrase:"difference between sql server 2005 and sql server 2008"The first two results returned will probably give you all the answers you require.
9 Sep 2010 by #realJSOP
Put the query into a stored proc, and pass the necessary parameters into that stored proc.
20 Sep 2010 by #realJSOP
I don't see where your problem is. Just get the value and set the checkbox. It really is that easy. If you have to preform another query, then perform the query.
21 Oct 2010 by #realJSOP
Use google, there are THOUSANDS of available examples of sending email with C#.
31 Oct 2010 by #realJSOP
It's not broken and you shouldn't try to "fix" it. SQL Server maintains the index of the last inserted item. It's supposed to be a unique value, and the only way that can be guaranteed is if you allow SQL Server to maintain that index. You *can* reset the value, but you'd have to reset it again...
7 Dec 2010 by #realJSOP
Three seconds for SQL Server to return a dataset is a LONG time. The more records you have, the longer everything is going to take, and that means binding as well.
3 Jan 2011 by #realJSOP
This question cannot possibly be answered here (in Questions & Answers) because the topic its too broad, and a variety of opinions can be expressed. Repost it in the appropriate forum so you can have a threaded discussion about it, or limber up your google muscle and research this thing yourself.
12 Jan 2011 by #realJSOP
Maybe you didn't correct configure the column. You have to specify the number of places to the right of the decimal, like this:decimal(10,2) - ten digits, with two to the right of the decimal point.EDIT ============I'm curious. If this was "the" answer (which it looks like it was),...
16 Jan 2011 by #realJSOP
Well, your insert code should probably be in a thread. You can save time by putting the thread into a class, and creating the SQL connection and command just one time. The body of the thread should be concerned with repeatedly stuffing the data into the database. It would go something like...
17 Jan 2011 by #realJSOP
Retrieve the text, send it to a stored proc, and let the stored proc search the applicable column for the text.
18 Jan 2011 by #realJSOP
The best time to use an ORM is: 0) When you don't care how badly a program performs1) You're willing to give up a certain amount of flexibility2) You know for sure and certain that there's no way on this earth that you're going to need to modify the generated code.
19 Jan 2011 by #realJSOP
You MUST use a web service to interact with a database from Silverlight. This link should get your started:http://msdn.microsoft.com/en-us/library/cc197940(v=vs.95).aspx[^]
20 Jan 2011 by #realJSOP
You seriously can't think of anything yourself? How about a simple "Hello world" project?
20 Jan 2011 by #realJSOP
I believe you have to clear the session cache on the site. Otherwise, sessions remain active until you actually shut down the browser instance that started that particular session (or maybe even all existing browser instances).
4 Mar 2011 by #realJSOP
Put the code into a try/catch block, and use the freakin' debugger.
17 Mar 2011 by #realJSOP
Try casting column1 to a varcharselect distinct cast(column1 as varchar(max)), column2...
18 Mar 2011 by #realJSOP
select top 3 id, name, percent from mytable order by percent desc
29 Mar 2011 by #realJSOP
Try this:ControlType control = (ControlType)Master.FindControl("controlID");And then you should be able to get the selected index.
31 Mar 2011 by #realJSOP
Yes, it's possible to build all of your sql dynamically. Whether or not you do it correctly is another question, and one I cannot answer.I would personally do it in a stored procedure, but that's just me.
14 Apr 2011 by #realJSOP
Do you mean from the sql side of things or the application side? You gotta be a lot more specific. And what do you mean by "orphaned" connections? As far as a .Net application goes, you should ALWAYS close a connection after using it. There are few reasons to keep a database connection open...
25 Apr 2011 by #realJSOP
I believe you can set quoted_identifiers and ansi_nulls inside the stored proc, so move those in there. You don't techniqally need the USE statement, so comment it out. Then, try your code again.
2 May 2011 by #realJSOP
The way I'd do it is *without* any of that sql stuff...0) Create an object that holds the data:public class SampleItem{ public DateTime SampleDate { get; set; } public decimal DepthFeet { get; set; } public decimal WaterTemp { get; set; } public SampleItem() ...
4 May 2011 by #realJSOP
Would it be possible to simply transfer the table as a binary file using FTP or TCP/IP, and then let the remote machine do all the database work itself?If you want to ensure some kind of recovery system (in the event the transfer is interrupted), you could send smaller files and alt least...
5 May 2011 by #realJSOP
You don't use "order by" in insert or update statements. It doesn't matter how the data goes into the table.
9 May 2011 by #realJSOP
This is entirely unanswerable.
9 May 2011 by #realJSOP
Because it's required to make it work. That's the best I know to tell you.
10 May 2011 by #realJSOP
I'm sorry, but that code resembles nothing I've seen that would compile, and has nothing to to with SQL, so that makes your tags wrong, too.
12 May 2011 by #realJSOP
You probably want to use a blob field - some web pages can be huge.
19 May 2011 by #realJSOP
If it's saved as an image, you could do this to get it on the screen (using the appropriate ImageFormat enum of course):// Set the content type and return the imageResponse.ContentType = "image/GIF";bytes.Save(Response.OutputStream, ImageFormat.Gif);
6 Jun 2011 by #realJSOP
Do you able to use google?
19 Jun 2011 by #realJSOP
We don't do poeple's homework for hem. It's not because we feel elite, but because you won't learn anything if we do your homework for you.
6 Jul 2011 by #realJSOP
Looks to me like you're not using comm2 after it's instantiated.
11 Jul 2011 by #realJSOP
"plz help me its argent"I don't care what shade of silver it is, that's not going to make us want to help you.As to your question, you could send the parsed string as XML data to a stored procedure and let sql server handle it.
12 Jul 2011 by #realJSOP
EASILY found on google. You could put this code into a Sql function if you want to:CONVERT(char(10), MyDateTime, 101) AS [Date], CONVERT(varchar(2), CASE WHEN DATEPART([hour], MyDateTime) > 12 THEN CONVERT(varchar(2), (DATEPART([hour], MyDateTime) - 12)) ...
18 Jul 2011 by #realJSOP
I think googling would have produced sufficient into to answer your question. I found this link when I googled "stored procedure faster than c# code?".http://www.codinghorror.com/blog/2004/10/who-needs-stored-procedures-anyways.html[^]
10 Aug 2011 by #realJSOP
Just say no to SELECT * in your SQL
26 Jul 2011 by #realJSOP
One way to effectively zero the columns any DataRow object.
1 Aug 2011 by #realJSOP
Is the server itself working? Can you ping the box?
9 Aug 2011 by #realJSOP
Let the database do it. If you set the loginID to be a unique column, trying to add an id that already exists will generate an error in the stored procedure which will be reflected to the client app as an exception (or maybe the return value from the stored proc will indicate a problem).
16 Aug 2011 by #realJSOP
Are you working with the guy that asked this question, or are you perhaps the same person using a 2nd account?how to do dashbaord reports using asp.net?[^]It's really coincidental that two people ask the same question on the same day.
25 Aug 2011 by #realJSOP
Something like this:select *from table1where column1 like '%project management books%'
26 Aug 2011 by #realJSOP
Your question doesn't exactly spell out what you want to do. Are you saying you want to create controls as specified from a SQL query? If so, you would have to do something like this:// assuming you've already retrieved your sql data into a DataTable object:bool haveCtrl = true;DataRow...
31 Aug 2011 by #realJSOP
I'm almost positive that you can't use MAX on a string. Try it this way:ISNULL(MAX(ProjectOverview.[Target Event Date - Date]), 'INACTIVE') AS [Target Bid Date]
1 Sep 2011 by #realJSOP
Try this:select id, name, address, sum(amount) from table2 group by id, name, address
9 Sep 2011 by #realJSOP
Well, did you google it to see before asking us to do it for you?
14 Sep 2011 by #realJSOP
Windows comes with software that essentially reads the screen for the user. Look under Start | Accessories | Ease of Access.
15 Sep 2011 by #realJSOP
Take a class - it's better than a web-based tutorial.
19 Sep 2011 by #realJSOP
You pass it as a string, but then in your stored proc, you have to use "dynamic sql":CREATE PROCEDURE [dbo].[spn_executeSQLExample] ( @tableName VARCHAR(100))ASBEGIN DECLARE @sqlStatement AS NVARCHAR(500) SET @sqlStatement = 'SELECT COUNT(*) FROM ' + @tableName ...
6 Dec 2011 by #realJSOP
if (yourquery.Trim().ToUpper().StartsWith("SELECT")){ // execute the query}
8 Dec 2011 by #realJSOP
Of course a stored proc can be made to time-out. Assuming you have a proerly designed and constructed database, along with a stored proc that actually works, it shouldn't time-out. Try running the stored proc inside sql manager express and see how long it should take to run.
12 Dec 2011 by #realJSOP
You can only communicate with a database via a web service. So that means you have to write one.Google is your friend.
14 Dec 2011 by #realJSOP
Write a Windows service that can get job info from the database, and then run the jobs on the specified schedules. Of course, you didn't describe the nature of the "jobs", so it's impossible to be more specific with suggestions.
19 Dec 2011 by #realJSOP
A simple google search would have revealed this CodeProject article:Save Image in MySQL DB using ASP.NET C #[^]
17 Nov 2014 by #realJSOP
How to fix this ANNOYING problem
5 Oct 2015 by #realJSOP
Yes, you CAN document your stored procs in C# code.
18 Mar 2016 by #realJSOP
This is a weird one. So I'm cruising along developing a MVC5 web site, and everything is going pretty well, including using stored procs from the database.Then I added a new call to the database. This call fails with the exception Keyword not supported 'initial catalog' when I try to...
18 Mar 2016 by #realJSOP
Weirdness. Without ANY changes to my code, it started working. I can only shrug my shoulders...
3 Oct 2016 by #realJSOP
Look at my recent article. It should be quite simple to convert to VB.Net.CSV File Parser[^]You could also just put it into a DLL assembly and call it from your VB app.As far as bulk inserts go, I would write a stored procedure and submit the records one at a time. That would be faster.
7 Oct 2016 by #realJSOP
In the following example, str will be "00:20:34"TimeSpan test = TimeSpan.FromSeconds(1234);string str = test.ToString();
17 Oct 2016 by #realJSOP
Google "SQL BlockCopy". I'm assuming you simply want to stuff data into the database without regard for duplicates or otherwise existing data in the table in question.If you're using stored procs and/or perform an update and/or an insert depending on whether or not the data already exists in...
18 Oct 2016 by #realJSOP
private static void EnsureVisibleRow(DataGridView view, int rowToShow){ if (rowToShow >= 0 && rowToShow
21 Oct 2016 by #realJSOP
0) What kind of idiot designs a SQL database to store a datetime as a nvarchar?1) Which "1" is the one you want to strip? At the beginning, or at the end? Do you even know what the actual purpose of the extra "1" is (why it's there)?2) The way your nvarchar string is shown, there's no...
25 Oct 2016 by #realJSOP
You don't need IF EXISTS - it's redundant. Simple remove the record and insert the new one.However, I would actually do it this way:-- try to update the recordUPDATE [mydatabase]SET ItemName = @itemName, Price = @price,WHERE ID = @ID;-- if no record was updated, insert it IF...
4 Nov 2016 by #realJSOP
Encrypt a Column of Data[^]
4 Nov 2016 by #realJSOP
IMHO, I would break it into smaller chunks.0) Insert a new testrun item, and get the resulting id from the database for the recently inserted item.1) Do a bulk insert on detail items with that returned testrun id.That would be easier to debug.Since "code" is part of your user ID,...
4 Nov 2016 by #realJSOP
Why are you going through that song and dance? Just write better sql code.0) Constrain and sanitize input data. Check for known good data by validating for type, length, format, and range.1) Use type-safe SQL parameters for data access. You can use these parameters with stored...
21 Nov 2016 by #realJSOP
Increase the SqlCommand.Timeout value. I typically just double mine when I run into this issue (however the default value is 30 seconds, and that is typically enough). You could also set it to 0 which indicates no timeout, but that can be dangerous, and lead to an app that hangs.Secondarily,...
22 Nov 2016 by #realJSOP
If your app uses SqlServer, there's no way around requiring the user to install some form of Sql Server, so...Add SqlServer Express to your installer's dependencies...- OR -Consider using SqlLite instead. Be aware that "lite" means exactly what you would expect - limitations on...
24 Nov 2016 by #realJSOP
This is a network or hardware issue - not a sql server (the software) issue, and certainly not applicable to c#.
25 Nov 2016 by #realJSOP
DO NOT migrate backwards. Access has more issues than the Hillary Clinton does with the FBI.All you have to do is make SqlServer (in one for or another) a requirement of using your software. Your installer can install it for them.Check this link that compares the different sql server...
28 Nov 2016 by #realJSOP
My guess is that you're setting the border style AFTER you've set the border itself.foreach (TableCell cell in row.Cells){ cell.BorderStyle = grdMaterials.BorderStyle; //
29 Nov 2016 by #realJSOP
Change the setting (turn off "prefer 32-bit") and see what happens.FWIW, installing the 64-bit version is required, but you should not have to change your code to use the 32-bit version if that's what's installed on the user's machine. You shouldn't have to much around with "prefer 32-bit"...
10 Dec 2016 by #realJSOP
Why don't you have the query that threw the error log it instead of making the app do it?
24 Dec 2016 by #realJSOP
I've never had performance issues with sql server that were not caused by something I've done. I don't use table valued parameters.You can either iterate the list and save the onbjects one at a time, or do like the first answer suggested, and serialize all the data into xml and pass the XML...
6 Jan 2017 by #realJSOP
You have to store the points in the database as integers (or floats, depending on which UI framework you're using). You're going to need fields for X, Y, Width, and Height, as well as a way to identify a given button.
9 Jan 2017 by #realJSOP
The server has to be configured to allow it. You have to contact the DBA that owns the server, and after it's properly configured, he can provide the appropriate connection string. However, any DBA worth his salt won't do as you ask, because it's more secure and auditable to have an outward...
13 Jan 2017 by #realJSOP
Parsing resumes is next to impossible due to the free-form nature of the documents. Add to that the fact that many people aren't detail-oriented enough to make sure they spell everything correctly, or that a given acronym could mean several different things, and that makes it even harder to do...
25 Jan 2017 by #realJSOP
Make sure your parameter and field types match (and they should be NVARCHAR).
26 Jan 2017 by #realJSOP
str = str.Replace("'", "\"");
31 Jan 2017 by #realJSOP
A scalar function to determine if a given DateTime is one of the ten US federal holidays, using SQL Server.
31 Jan 2017 by #realJSOP
Using common table expressions to build data from thin air.
6 Feb 2017 by #realJSOP
If I understand your question, you want to skip rows that have an "M" in a certain column.Change your if statement from this:if ((Myrow.Cells[8].Value.ToString()) == "M"){ //What should I do here?}else{...to this:if (Myrow.Cells[8].Value.ToString()) !=...
13 Feb 2017 by #realJSOP
I've found that it's a good idea to do this when you're changing the field contents:select [desc] + ' ' + [compo] AS Description from vidros
20 Feb 2017 by #realJSOP
I gotta say this doesn't seem like a very good idea. If your app gets hacked, someone could write a stored proc to your database that a) wipes all the data, and/or b) steals all the data, and/or uses the sql server as a spam bot, and/or any other number of evil deeds.
22 Feb 2017 by #realJSOP
If it were me, I'd pass the selected items (as a List) to the new form via the constructor, and let THAT form perform the SQL query.