Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MSSQL Select one Field

Posted on 2010-08-16
7
Medium Priority
?
538 Views
Last Modified: 2012-05-10
I am building a Auto-It script that connects to ms sql and returns a field for a variable. Here is my query:

SELECT TOP 1 sde_id FROM  sde.SDE_process_information
Displays:

sde_id
116648


But I would like it to just return 116648 only. How do i get results for just one field without the row name.
Thanks


Sqlserver 2008
0
Comment
Question by:CityInfoSys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33450263
Without looking at your script, it's very hard to change it.
Normally, a query would only return the value, so your script must be specifically inserting the column name.
Does it actually return as a string with embedded line break?
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 33450433
if you are running via sqlcmd try the -H parameter...alternatively  use a stored procedure and an output parameter,,,
0
 
LVL 13

Expert Comment

by:George K.
ID: 33452354
Have a look at these functions


_CreateTable - create a new table in the database.
_CreateColumn - create a new column in a table in the database.
_DropCol - delete a column and its contents from a table in the database.
_DropTbl - delete a table and its contents from the database.
_CountRecords - returns the number of records in a column that match a specific search parameter.
_CountTables - returns the number of tables that are in the database.
_GetColNames - returns an array with the number of columns in the first array element and all of the column names in the specified table from the database.
_GetTblNames -returns an array with the number of tables in the first array element and all of the table names in the specified database.
_GetColVals - gets all of the values in a specified column in a specified table from the database.
_GetColCount - returns the number of columns in a specified table in the database.
_GetColType - returns the data type of a column specified in a table from the database.
_GetDBNames - returns an array with the number of databases in the first array element and all of the database names in the specified server.
_ChangeCon - changes the connection object to allow for a different username, password, server, or database.



http://dailycupoftech.com/2007/04/18/mysql-data-manipulation-with-autoit/




0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 13

Expert Comment

by:George K.
ID: 33452355
Can you paste your code?
0
 
LVL 1

Author Comment

by:CityInfoSys
ID: 33455071
Here is the code I am still working on. Mainly I need to figure out the query part. Also this is MSSQL not mysql.
Thanks
;AutoIt Code

$Query = "SELECT TOP 1 sde_id FROM  sde.SDE_process_information"

Func SqlConnection()
	If $adoCn.State = $adStateOpen Then $adoCn.Close
	$adoCn.ConnectionString = $Conn
	$adoCn.Open
	If $adoRs.State = $adStateOpen Then $adoRs.Close
	$adoRs = $adoCn.Execute($Query)
	If $adoRs.State = $adStateOpen Then
		$J = $adoRs.Fields.Count - 2 
		For $K = 0 To $J
		$Output = $Output & $adoRs.Fields($K).Name & @TAB
		Next
		$Output = $Output & @CRLF
		$Output = $Output & $adoRs.GetString(2, -1, @TAB, @CRLF, "Null")
		$adoRs.Close
		GUICtrlSetData($EditResults, $Output)
	EndIf
EndFunc   

Open in new window

0
 
LVL 13

Expert Comment

by:George K.
ID: 33457763
I 've had a very fast look to your code.
Maybe delete this line?:
$Output = $Output & $adoRs.Fields($K).Name & @TAB
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 33459171
Delete 4 lines otherwise you have a loop that does nothing. You also get an extra CRLF

delete
            For $K = 0 To $J
            $Output = $Output & $adoRs.Fields($K).Name & @TAB
            Next
            $Output = $Output & @CRLF

so you end up with
;AutoIt Code

$Query = "SELECT TOP 1 sde_id FROM  sde.SDE_process_information"

Func SqlConnection()
	If $adoCn.State = $adStateOpen Then $adoCn.Close
	$adoCn.ConnectionString = $Conn
	$adoCn.Open
	If $adoRs.State = $adStateOpen Then $adoRs.Close
	$adoRs = $adoCn.Execute($Query)
	If $adoRs.State = $adStateOpen Then
		$J = $adoRs.Fields.Count - 2 
		$Output = $Output & $adoRs.GetString(2, -1, @TAB, @CRLF, "Null")
		$adoRs.Close
		GUICtrlSetData($EditResults, $Output)
	EndIf
EndFunc   

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question