I've got a table with 45 columns and 600,000 rows. I need to tune up a SELECT statement from this table, which for now lasts about 41 seconds. I need to return all the columns and i don't use *. This table has no keys, constraints or indexes. It also has no unique value which could be used as a p...
DELIMITER $$
DROP FUNCTION IF EXISTS `GetAncestry` $$
CREATE FUNCTION `GetAncestry` (GivenID INT) RETURNS VARCHAR(1024)
DETERMINISTIC
BEGIN
DECLARE rv VARCHAR(1024);
DECLARE cm CHAR(1);
DECLARE ch INT;
SET rv = '';
SET cm = '';
SET ch = GivenID;
WHILE ch > 0 DO
...
I was trying out a query and it was returning an error which I cannot explain. (5 th query ).
Can someone help me understand what is causing the error.
DROP TABLE #temp
SELECT * INTO #temp
FROM
(
SELECT 'A_100' Col
union all
SELECT 'A_101'
union all
SELECT 'A_102'
union all...
@ypercube I did a quick search and didn't spot a better candidate so I closed it. Should also suggest TRY_CONVERT if 2012+ (I'm going to edit my answer)
@swasheck awesome
@ypercube edited here is probably the better dupe (too late for me to fix it now):
I assume that RValues is a string column of some type, for some reason. You should fix that and store date data using a date data type (obviously in a separate column than this mixed bag).
If you can't fix that, then you can prevent what Damien described above by:
CASE WHEN ISDATE(RValues) = 1 ...
@bluefeet any chance you can make this question point to this duplicate instead (or in addition, if that is possible after the fact)?
Sorry, it is this question that I closed as the wrong duplicate. I think this answer describes the problem and lists better workarounds more concisely. IMHO.
It's about dates and not ints, but the underlying problem is the same.
We have two server with identical hardware configuration and SQL server configuration.
The only difference in the server's being:
Server SQL1 - 256 GB RAM
Server SQL2 - 128 GB RAM
The same database has been restored on both servers. The query execution plan for a query on both servers is diffe...
@ConcernedOfTunbridgeWells probably fine, not sure yet. I'll be away for a week in November but haven't booked yet. Fix the date and I can arrange my schedule.
I want to implement something like the following:
In this package, I want to loop through a list of database names, dynamically modifying connection manager settings.
However, the first failure on "Test Connection" will halt and fail the package execution.
But I'd like to continue my Foreach ...
@MichaelJSwart Is there a reason you're using an Execute SQL task to test whether the connection works vs a script task? Easier to control the failure there
@billinkc Okay, so why is a script task easier? I don't understand how the flow control is any different. And the test connection sql is just "SELECT @@SERVERNAME"
Well, you can control the flow with variables yes. And you also don't need to set the MaximumErrorCount to 0, which can be fairly dangerous if some other thing fails. But, I can't say what was the specific thing that @billinkc wanted to say
Lamak is correct on all accounts. My theory was that with a Script Task, you were in control of your own destiny versus trying to stamp down the default SSIS behaviour of raising an error
Once I have a few minutes, I'll gin up a suitable package to demonstrate both approaches
We had all sorts of problems like that at Wand. We were using Telerek reporting for some reason and it would hand back parameters as XML strings. Which sucked the big one.
So Jamie Thomson's Verify A Connection Before Using It was helpful here.
I replaced the Test Connection task with a script task. The script task was almost exactly like Jamie's script except that I
Only used one connection manager, not all of them.
the task result was always success
I set a n...
So I have an application that automatically creates a new database after the database it is currently in reaches a fixed number of rows. I need to be able to automatically assign a user within the installation the db_datareader role for the automatically created database. I'm kind of at a loss he...
I am not sure what they did or how. Charter is supporting that they pushed a firmware but mine does not show it updated. This caused something internal to one particular model (lucky me) and everyone has the issue no matter what ISP they are on.
I've had no really issue with it until now. I was not aware they could push out something to this magnitude that their product does not even show it received an update.
I have workaround until I can find money to buy another one I guess.
@AndyEvans people can downvote for whatever reason they want. Maybe they don't like the color of the shirt on your gravatar. Don't worry about it man. — Zane13 secs ago
@Lamak I don't understand that behaviour either but well, people can both downvote and upvote for whatever reason they like, can't they. Including "compensation" voting.
"Just write the code to do the thing." This isn't really an answer, it should be a comment. Primarily because the biggest obstacle in this case is going to be creating a #temp table with a dynamic number of columns with dynamic names and data types. You'll need to create the #temp table in dynamic SQL, which means you'll have to also insert and do anything else you're going to do with this #temp table - throughout the entire procedure - inside dynamic SQL. Teaching someone how to change a tire is not just "here's the jack, there's the tire iron, go nuts!" — Aaron Bertrand6 secs ago
@AaronBertrand They seem to use "stored proc" and "function" interchangeably. The first time it was a stored procedure, in the edit they said "function".
I recently wrote a query that surprisingly filled our tempdb. I was simply doing a string comparision on several thousand records, and I imagine because the strings where so long that the transactional data in the tempdb filled.
I would like to prevent this in the future by adding logic to my qu...
Do you want to think about maybe being sure that this is actually what caused the problem before you write code that supposedly cures the "problem" you're not even sure is the problem? — Aaron Bertrand22 secs ago
@AaronBertrand Would it be possible to add such a check anyway? SQL is a declarative language, so it would probably need to be some kind of a query hint. Are there such hints in T-SQL?
@AndriyM you could simply wrap the problematic query (I assume he knows the exact query that he believes caused the problem) in an IF conditional that checks the status of tempdb size/space before running. This would simply prevent the query from running, not cancel the query after it started. I don't think you could put anything in the query itself that said "uh oh, I'm using too much tempdb, better bail."
@JNK you should just tell them that no matter what, it's a box of chocolates, unless you have an explicit order by. What you've told them so far is just promoting that they should be writing queries without it in the first place. :-)
Checking MyISAM file: ./table_data_cache.MYI Data records: 33978815 Deleted blocks: 0 myisamchk: warning: Table is marked as crashed and last repair failed - check file-size myisamchk: warning: Size of indexfile is: 3853438976 Should be: 2048 - check record delete-chain - check key delete-chain - check index reference - check data record references index: 1 myisamchk: Unknown error 126 myisamchk: error: Can't read indexpage from filepos: -1 - check record links myisamchk: error: Recordlink that points outside datafile at
@user965347 not here, I'm afraid. I'd suggest posting a question on the site, but those are just spam-bait for some recovery toolbox software that promises to repair/recover databases but can't possibly deliver. Next best option: use a real database.
...you know, or, restore from backup. You have backups, right?
Aaron, can you give us some examples of optimal settings to ensure that the idle mode doesnt cause substandard process? Our system is written in stored procedures for every process. So our understanding is that stored procedures have executionplan and they carry throughout. Shouldnt this avoid this problem? If not, can you give us an example of an executionplan that stands alone? — Nick Uresin42 mins ago
where to start
I think by just logging out
Also this guy, he's been trying to get this working for two days? And didn't think to search for the error message?
I've looked through the Web for the better part of 2 days trying to find how to connect to SQL Server 2012 that came with VS Express 2013 for Desktop.
Based on some things I found on various sites, in my connection string (starting with "") I've tried
Server=.\MSSQLEXPRESS;Database=BrightStar...
We get a flat file of data from one of our vendors. We load via SSIS and then have a process that joins on one of the raw data columns. We have a list of the expected values but just realized that the vendor is altering the expected values - ever so slightly. So we have items that are getting lost. We want to do some fuzzy matching. It looks like the vendor is using a similar pattern so I wrote the following query to "match" the data -- sqlfiddle.com/#!3/170c16/4
the data they send us always has that "21" characters either on the front or end of the string we join on.
We also get rows without that "plan from..." - I'm trying to account for all cases via some matching
I'd prefer not to assume the length is 21 but not sure how else to fuzzy match - ideas?
I have 2 fields I want to send values to within a WHERE statement.
If a variable = 0 then set 2 field values to 100.
If the variable = 1 then set those same 2 field values to 101.
In my imaginary world, somehow this would worK:
Where CASE WHEN @ReportType = 0 THEN
od.StatusCd = 100 AND odm...