Fix restore invalid column reference editor by clicking Ok? - sql-server

This SSIS job essentially exports data from an oracle PLSQL database to a SQL Server database.
Whenever I change something in the WHERE clause of the query that will be used for the bulk insert, I get the following screen. I just click 'Ok' and everything's fixed.
Two questions: why do I get this error every time I change the query? I'm not changing the columns or the size. The output is not affected since I'm not touching the columns.
Is it a valid fix just to click 'Ok'? Whenever I see the red X after changing the output query, I literally just double-click on the SQL Server Destination and click 'Ok'.
This is the query. I simply change the WHERE clause; for example, trunc(sysdate)-2 to trunc(sysdate)-1
SELECT
datetime
,EmplCode
,TotalSales
,TotalRev
TotalTax
FROM Employee
WHERE
Employee.EmplCode like 'STX%'
and trunc(Employee.DATETIME) = trunc(sysdate)-2 --This is what I change
Thanks.

Did you rename the columns in the where clause? Are there functions in the where clause? Please show the code in the where clause.
If you right click on the task, and choose advanced, you can view/edit the input and output columns. You can see then see the effect of clicking on the 'OK' button. SSIS is either renaming or changing the data type of one or more columns. Its probably ok but you should be aware of what SSIS is doing. Trust but verify to quote a former president....

Related

SQL Server Mgmt Studio shows "invalid column name" when listing columns?

I'm used to scripting in Python or Matlab, and my first couple hours with SQL have been infuriating. I would like to make a list of columns appear on the screen in any way, shape, or form; but when I use commands like
select *
from "2Second Log.dbo.TagTable.Columns"
I keep getting the error:
Invalid column name '[the first column in my table]'.
even though I never explicitly asked for [the first column in my table], it found it for me. How can you correctly identify the first column name, and then still claim it's invalid!? Babies will be strangled.
This db was generated by Allen Bradley's FactoryTalk software. What I would really like to do is produce an actual list of "TagName" strings...but I get the same error when I try that. If there were a way to actually double click the table and open it up and look at it (like in Matlab), that would be ideal.
Echoing juergen's suggestion in the comment above. It looks like you're running the query on the master database, not the 2Second Log database that actually has your table. (You can tell this by looking at the database in the dropdown in the top left of your screenshot). Two things you can do:
Change the dropdown in the top left to 2Second Log. This will target your query to a different database
Put your database name in brackets as suggested by juergen i.e. select * from [2Second Log].dbo.TagTable
As an side, if you're looking for a good SQL tutorial, I highly recommend the Mode SQL tutorial. It's a fantastic interactive platform to get your SQL feet wet.
always use brackets when names/field have spaces or dashes.
select * from [2Second Log].dbo.TagTable

how to load a variable from "Execute Sql Task" in SSIS package

I have some variables (at package level, at dataflow level, doesn't matter) and I need to load them by running an Execute Sql Task.
I added an Execute Sql Task, I have wrote my sql statement in filed SqlStatement, I have changed the ForcedExecutionValueType to string.
Now I want that when the Execute Sql Task is executed the return value that that select returns, to be the exact value for my variable.
example:
Select employer_name from employers where id=1
Returs="John Doe"
value for #employer_name must be "John Doe"
Any hints?
Your more detailed discussion of the issue is a little difficult to follow, so I aplogize if my following steps cover items with you are already familiar.
Steps:
Under the Control Flow tab, drag over an Execute SQL Task and open it.
Select General on the left.
Define the Connection (based on a database source created in Connection Managers below).
Define the SQL Statement.
For Result Set, select Single Row.
Select Result Set on the left.
Select the Add button and notice that a new record was added above.
Under the Result name column header for the new record, change "NewResultname" to "0".
Under Variable Name column header for the new record, select either an existing User variable you've already created or scroll to the top and create a new one.
Select OK and you're done.
Running the Execute SQL Task by itself will now populate the variable. Make certain you've verified that the SQL will return only one value and no more. Otherwise, you will need to modify your SQL with "TOP 1" in it to be on the safe side. When multiple values are expected, then you to apply a variable defined with a Data Type of "Object" and use "Full Result set" instead of "Single Row" in the Execute SQL Task.
Hope this helps.

Refreshing a table in SQL server management studio

I have opened a table in SQL server management studio express.
How do I update it?
As changes made outside the studio application do not show unless I close and reopen the table. Surely there must be a better way of doing this?
In SSMS (SQL Server Management Studio) press Ctrl + R
In Visual Studio Press Shift + Alt + R
I am not sure if I understand exactly what you want, but if you want to see the changes, the query that loaded the table has to be re-executed. You can do this by clicking on "Execute SQL" (or selecting it from the context menu).
Depending on what you mean with "opening the table" (select top x rows, edit top x rows, etc ) you also might try to hit F5 (works for "Select TOP x Rows") - which simply executes the previous statement.
As a rule, manually editing data in SQL Server is a bad practice.
It's not repeatable. Anything you do is limited to your window and once it's gone it's gone.
It's easy to make mistakes. Click the wrong cell, fat-finger a decimal point, etc.
A much better solution is to create and save insert or update scripts. These are editable, reviewable, and rerunnable.
If you need to recreate your database or replicate something now, you need to manually type in all the same values you typed in before. If you script it out, you just run the script and can have the same data as many times as you can hit F5.
It is much easier if you just create a query referencing on that table. Then create select statement giving all rows from that table.

Data has always changed(SQL Server Management Studio)

I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine)
When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved... Optimistic Concurrency Control Error" If from here I say "Yes to commit changes to database anyway" I get "No row updated... The updated row has changed or been deleted since data was last retrieved"
It's a very annoying little thing, cause I don't like having to look up RIDs and then make an update statement(and possibly having to worry about escaping 's by hand)
Is there some way to turn this concurrency checking off or something? I know the row wasn't updated or anything, and I tried completely closing Sql Server Management Studio and reopening to no avail, and also tried refreshing the result pane, or refreshing the column view. Nothing gets rid of this error, but if I do a "update ... set ...=..." then it works, so I'm not really having any concurrency error..
I had exactly the same problem. It looks like this article was pretty good at solving it. Seems all sorts of buggy things in some versions.
See: You may receive an error message when you try to use SQL Server Management Studio to update a row of a table in SQL Server 2005.
The table contains one or more columns of the text or ntext data type. The value of one of these columns contains the following characters.
Percent sign (%)
Underscore (_)
Left bracket ([)
The table does not contain a primary key.
http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/7bf48a75-58a0-41d7-b514-b804a49ae8ff/
it seems to be a bug in SSMS I don't think I have over 4000 characters, but I can confirm this only happens on rows that have more data than others.. there seems to be some abritary limit that I can't quite put my finger on..
So, plainly SSMS is complete crap. I'll be looking for a new SQL manager..
You shouldn't edit a table directly from the table view.. you should use an UPDATE sql command.

Edit data from result grid

I would like to edit data directly from result grid in ssms. eg:
When I execute SELECT TOP 10 * FROM some_table, I want to edit data directly from result grid.
I don't want to open some_table and edit from there.
I know that result grid is read-only, but maybe someone written addin for it.
You can't edit the data from within the result grid. You'd have to go via the "open table" route if you want to edit the data manually instead of using UPDATE/INSERT SQL statements.
Is there a reason you specifically want to use the result grid instead?
You can specify a query when you go via open table to limit the results if that's your reason? There's a "Show SQL Pane" button in the top toolbar you need to select (square box with "SQL" written in it).
I have very large database (70+ GB) with so many tables.
I'm using Red Gate's SQL refactor for intellisense and few other things.
It's so boring to type in update sql statements every time I need to change single field.
It also takes some time to find that table in the Object explorer.
Intellisense doesn't work when I use "Show SQL Pane".
I'm new to SQL Server and have used the Oracle product 'PL/SQL developer' by All Round Automations at a previous job... It would allow you to do a SELECT in the query window and then simply add "FOR UPDATE" to the end of your refined SQL SELECT and 'ta-da' you can now edit the results in a nice grid. No need to Open Table View, click the SQL button, paste in the SQL you you have been working on and then hit execute ;)
EMS SQL Manager for SQL Server allows to update data directly inside a results grid.
This tool is boring for typing new requests (poor intellisense and error management) but fine for this. I always have the two tools opened.
If you right click on the table and choose edit top 200 records, it produces a result screen with an query.
Add to this your query and then you can edit the records in the result screen.
Also you can change the 200 to a number you want (2000).
The "results" pane is not just results.
Results in text
Assorted time and IO statistics
Estimated and actual execution plans
Row counts, Error messages, PRINT output
etc
This is why they are separate.
Feel free to write your own add-in :-) Or here
SQL Server ISN'T Access!
When you run a query and get the results - thats exactly what you are doing, reading the data, not opening the table for editing. Can you imagine the necessary transactional control around allowing the results window to be edited? The locking would probably grind SQL to a halt - I hope no-one ever writes that kind of add-in!

Resources