I would like to have multiple select statements in one tab.
I will give a example.
SELECT * from TableA
SELECT * from TableB
SELECT * from TableB
Result I would like to see:
Result from table A
Result from table B
result from table C
Is it possible to have something like that? I dont want to open multiple tabs, I would like to have multiple results in one tab in text mode.
Just click this button:
or Alt + x
I also need an answer for this: I want the results from several different queries, all in only one single tab, in text mode.
If that is not possible, getting all results logged to a single text file on the client filesystem will work too.
I would like to connect an autocomplete text field to an SQLite database. The user should be able to type in a few letters and then select the item they would like to add from possible suggestions. Once the user adds the item (by pressing a button), an SQL query should retrieve other values from the selected item row.
Example of database table row.
To summarise, I would like the following:
An autocomplete component to provide suggested items (ItemName from database) after the user types a few letters
Perform an SQL query to retrieve values (Salt and Sugar from database) and keep a running total of salt and sugar. Theses values should then be added to a table containing 2 rows with 2 columns, as follows.
Salt | [value from database + total salt]
Sugar | [value from database + total sugar]
I would therefore appreciate therefore any advice and guidance on how these could be implemented.
You need to use a select query on ItemName specifically:
select `ItemName` from tablename
Then use that data for your auto complete code.
When the action listener for the auto complete fires just issues the query
"select * from tablename where ItemName='" + mySelection + "'"
Then use the column values in the returned row. You also need to deal with a case of nothing being returned if the user typed in something that isn't available in the list and pressed "Done".
I am using mail merge to input data from an excel sheet. Everthing works great and I can access my variables using «MyMergefield»
Now I need for each letter generated to look into another excel file and do a query that will take the «MyMergefield» as a query filter SELECT FROM x WHERE field1 = «MyMergefield»
The way I am proceeding is "inserting a quick part" => "Field" in my word document.
In the quickpart dialog, I choose "DataBase", then I choose my excel file.
once the data source is chosen, There an option to change the request parameters, I click on it and I get the filter configuration popup where I can choose the field (from the excel sheet), the operator ("equals" in this case). Then there's the compare with field. In my case its not as simple as comparing to as string. Its comparing to a mail merge field.
I tried the following syntax:
«Myfield»
MERGEFIELD Myfield
MERGEFIELD "Myfield"
{MergeField Myfield}
{ MERGEFIELD Myfield}
None worked, it complained that it did not find any match so it did not insert the database (Of course it will not find any match to the syntax if I don't run mail merge)
I did look directly in the openxml file of an existing example (because I can't edit existing quickpart - Correct me if Im wrong) and the database query looked like:
FROM `Candidates$` WHERE ((`column` = '</w:instrText>
...
<w:instrText xml:space="preserve"> MERGEFIELD Myfield</w:instrText>
</w:r>
Any ideas? Thank you!
Is there a shortcut for adding commas for values for IN clause? e.g. if my query SELECT * FROM Persons WHERE Id IN(.....)
and I've copied
356
9874
5975
9771
4166
....
Person's Id values let's say from some Excel file, How can I quickly add ',' comma to the end of each line, so I can paste it IN(....) clause?
Here's what you need to do:
Put your cursor one space after the 356 (you'll see what you need that extra space in step 2).
Hold down ALT + SHIFT and click the down key for as many numbers as you have. You should see a blue line just to the right of your numbers. This is why you needed the extra space after 356 - so that you can just arrow down the entire list without having to move left or right.
Release the keys, and press the comma key. A comma should appear in all of the lines.
You can use this method to add quotes or other characters to your SQL queries as well.
I use this in SSMS 2014;
I am not sure if this can be done in previous versions
Yeah, that's always a pain.. There are a few things you can do:
insert commas in the cells to the right of the numbers in Excel and copy them with the list into SSMS
in Notepad++, copy the list with values and click CTRL+H (find and replace), in the Search Mode box click Extended. In the Find box type "\n" (without quotations) and in the Replace with it with a comma ""
Hope this helps!
Since SSMS 2012 you can "draw" a vertical line at the end of the code using the mouse while pressing the ALT key.
After that, just press the comma key and that's it.
I have resolved this issue by applying this query
select Concat(Id,',') from user
If you want to concatenate all rows into one you can apply below query:-
Select SUBSTRING(
(
SELECT ',' + Cast(id as varchar) AS 'data()'
FROM users FOR XML PATH('')
), 2 , 9999) As users
Write a little program, like the one below, and fire it off from Launchy.
I wrote mine in C# - called it Commander... probably both the best name and best program ever written.
using System;
using System.Windows.Forms;
namespace Commander
{
internal class Program
{
[STAThread]
private static void Main()
{
var clipboardText = Clipboard.GetText(TextDataFormat.Text);
Clipboard.SetText(clipboardText.Contains(",")
? clipboardText.Replace(",", Environment.NewLine)
: clipboardText.Replace(Environment.NewLine, ",").TrimEnd(','));
}
}
}
Compile the above and reference the resulting Commander.exe from Launchy.
Once referenced:
Highlight a column of characters, and cut or copy the text
Summon Launchy (Alt-Enter, if you're using the default shortcut)
Type Commander
Paste
Enjoy your comma separated list; like use it in an IN statement somewhere
Type Commander again from launchy with a comma separated list, and it will reverse the operation. Read code... it's kind of obvious :)
Some good answers here already but here's some more:
... Person's Id values let's say from some Excel file ...
If you're copying from Excel its sometimes easier to add commas (or speechmarks) or whatever in Excel before copying.
e.g. in the cell to the right do
=A1 & ","
Then copy that formula all the way down the list.
Also Notepad++ is great for this sort of thing, you can record a macro to do one line, and then run it N times:
In Notepad++ go to the start of the first line
Select Macro - Start Recording
Do the right keypresses - in this case: End, Comma, Down, Home
Select Macro - Stop Recording
Select 'Run a Macro Multiple Times ...'
It will by default show 'current recorded macro' (the one you just recorded)
Tell it how many times you want it, then off you go
I have a report which is just one page per record. The record is chosen using a parameter.
On this report I have space for 4 images, I have a dataset called "AdditionalPhotos". I would like to put the image from the first four rows of this dataset into each of the spaces on the report.
To do this, I planned on using an expression with a function like : First(Image), Second(Image), Third(Image), Fourth(Image). I now realise that SSRS only supports First() and Last() so using some advice from another forum post : http://social.msdn.microsoft.com/Forums/sqlserver/en-US/20493945-578a-4d83-ae3b-e603a3473ac6/nth-row-element-in-a-dataset-ssrs
I have implemented another dataset which contains the same query as the "AdditionalPhotos" but with only 2 columns "ID" and "RowNum". Using this expression I can see a Photo Source field in a textbox, which is great, so the syntax is working.
=Lookup(1,Fields!Row.Value,Fields!Source.Value, "AdditionalPhotos")
In the value field for the image I have :
=Lookup(1,Fields!Row.Value,Fields!Image.Value, "AdditionalPhotos")
This doesn't work, I just get a red x icon in the image box of the report. I have the correct MIME type setting and have confirmed this by changing the expression for the image box to :
=Fields!Image.Value
Any advice or suggestions would be great.
In your SQL you can use the ROW_NUMBER() window function to generate row numbers based on an order and/or a partition so that you can select which image you want where.
Something like:
SELECT Image,
ROW_NUMBER() OVER(ORDER BY id) AS rownum
FROM imageTable
See:
MSDN - ROW_NUMBER (TSQL)
MSDN - OVER Clause