How Do Select Data From My Database By IDs
Dec 14, 2007
How do i select data from my Database "HPDB.mdf" where the ID is 13, 14, 15?
I try to do it in the aspx way, but i got a conversion error:
Conversion failed when converting the nvarchar value '13, 14' to data type int.
asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="%$ ConnectionStrings:csHPDB %"
SelectCommand="SELECT * FROM [mgr_table] WHERE ([ID] IN (@ID))"
SelectParameters
asp:Parameter DefaultValue="13, 14, 15" Name="ID" /
/SelectParameters
/asp:SqlDataSource
asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
/asp:GridView
Anybody know how to solve this or do it in Visual Basic way? please help me. Thanks.
View 10 Replies
ADVERTISEMENT
Jan 31, 2008
Hi everyone..i m new to this field.. can anyone explain me with simple example onhow to insert,update,select data from the sqldatabase? i m using vwd 2005 express edition along with sql express edition. plz explain the simple example with code (C#) including how to pass connection strings etc.thank you.jack.
View 6 Replies
View Related
Sep 29, 2014
I'm trying to extract data from our database for the number of phone calls our reps are doing.
In counting the calls I only want to include up to 3 calls to the same customer (field name is CompanyID) per day - anything more than this is ignored.
The query at the moment is something like:
SELECT COUNT(CallID) AS CallCount FROM Sales_Calls WHERE CallDate >= '2014-09-01' AND CallDate <= '2014-09-30' AND RepID = 1
Using MSSQL 2012.
View 13 Replies
View Related
Apr 4, 2006
i am facing a problems, hope that anyone who know the answer can help me.
i am using sql server 2000 and vs.net. i wan to retrieve a data from the table which only select 3 top row based on their different contingentID. the table have different contingent and each contingent have 5 row data. i wan to retrieve 3 top row based on the total group by contingentID and sum up the total to order by the total and generate the ranking based on total. what i can do is only retrieve every row of data in that table. so anyone know the answer please help me, or if u dun understand my question , can message me..thank your
Skyline...
2006-04-04
View 3 Replies
View Related
Oct 8, 2007
Hi friends,I need to select columns for specific data from all tables in DataBasePls give me reply asap Regards,M.Raj
View 4 Replies
View Related
Jan 30, 2006
Hi there, I have installed Sql server 2005 developer on my machine which already has a Sql server 2000 installed on. Now i am trying to query the Sqlserver 2005 data(Ex: from Person.Address located in AdventureWorks database) in Sqlserver 2000 query analyzer:
When i try as Select * from Address it said invalid object.
But when i explored AdventureWorks database in the Management studio i see it as Person.Address!!! i don't understand what is a Person in Person.Address??? any clues on this?
So as a test when i ran select * from Person.Address it did work and i saw the results in query analyzer.
Can any one help me understand about this confusion?
Thanks-L
View 1 Replies
View Related
Jul 20, 2005
Dear list,I am trying to get the names of the tables and the column names from thecode below for a database but it is not working. When I run the querybelow the column titles are delivered but there is no data. I think thismight be a premissions issue. Has anyone run into this before?Thanks in advance.Use Test_db/* Provides Table Name, Column Name, Extened Description */Select a.name as tbl_name, b.name as column_name, d.name as data_type,d.length as length, d.xprec as prec, d.scale as scale, b.usertype,b.scale, c.valuefrom sysobjects as a inner join syscolumns as b on a.id=b.id inner joinsysproperties as c on b.colid=c.smallid and a.id=c.idinner join systypes as d on b.xtype=d.xtype
View 2 Replies
View Related
Sep 21, 2007
I have a problem....SOMEONE PLEASE HELP!
Here is the setup.
Text Box: User enters in customer transaction number
Button: User clicks button to display information about the customer
Now the database has a lot of unique customer numbers. What I am trying to do is take what the user enters so it can search the database and pull out that customers information. I am having a hard time getting that information from the textbox. Any suggestions! Here is what I have so far.
Private Sub btnViewFlow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewFlow.Click
Try
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.DataSet11 = New links.DataSet1
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation id=<14852>;packet size=4096;user id=<userID>;password=<Strong Password>;data source=ZRTPD0WB;p" & _
"ersist security info=False;initial catalog=DTR"
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "DTR_Document_Summary", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("DocumentId", "DocumentId"), New System.Data.Common.DataColumnMapping("PartnerId", "PartnerId"), New System.Data.Common.DataColumnMapping("PartnerName", "PartnerName"), New System.Data.Common.DataColumnMapping("Direction", "Direction"), New System.Data.Common.DataColumnMapping("TranSet", "TranSet")})})
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "SELECT DocumentId, PartnerId, PartnerName, Direction, TranSet FROM DTR_Document_S" & _
"ummary "
'WHERE (DTR_Document_Summary.PartnerId = 'txtPartnerId.text.toString')"
'THE STATEMENT ABOVE DOESNT WORK
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'DataSet11
'
Me.DataSet11.DataSetName = "DataSet1"
Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()
'Open the connection
SqlConnection1.Open()
TextBox1.Text = "Connection Open"
'Populate DataSet11
SqlDataAdapter1.Fill(DataSet11)
TextBox1.Text = "DataSet11 has been filled!"
'Display Data
DataGrid1.DataBind()
TextBox1.Text = "Here is your requested information"
Catch ex As Exception
TextBox1.Text = ex.Message
End Try
'Close the connection
SqlConnection1.Close()
End Sub
View 6 Replies
View Related
Apr 8, 2008
I would like to create a table which can store a VLOB or BLOB.. which are pictures and images.. How do I insert them into the database and how do I select them into the data base for playing in a media player
I really do not have a background on this.. much.. I just know how to connect to a database and insert texts.. and updating and stuffs...
View 3 Replies
View Related
Dec 18, 2007
Hi,
Is there a way in SQL Server 2005 to use a select statement to fetch data from a table in another Server while running the query in one Server.
Like using a database Server Link in oracle...
Thanks
Pramod
View 8 Replies
View Related
Aug 28, 2015
I am unable to the access on table even after providing the SELECT permission on table.
Used Query by me :
Here Test is schema ; Card is table ; User is Satish
To grant select on Table
GRANT SELECT ON TEST.Card TO satish
Even after this it is not working, So provided select on schema also.
used query : GRANT SELECT ON SCHEMA::TESTÂ TO Satish.
View 8 Replies
View Related
Dec 7, 2006
HiI have a query that is performing very strangely.I f I put a top statement in it returns rows,soSelect top 10 * from .......returns 10 rowsbut without it then no data is returnedSelect * from ..........returns 0 rows.
View 1 Replies
View Related
Mar 21, 2007
The error message:
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for data set 'TestID'. (rsErrorExecutingCommand)
For more information about this error navigate to the report server on the local server machine, or enable remote errors
The log file reads:
---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Query execution failed for data set 'TestID'. ---> System.Data.SqlClient.SqlException: SELECT permission denied on object 'TableID', database 'Database', schema 'dbo'.
***Background***
General Users got an error message when trying to access any reports we have created.
All admin have no problems with the reports. Users (Domain Users) are given rights (Browser) to the reports and the Data Sources (Browser) and yet cannot view the reports.
An error has occurred during report processing. (rsProcessingAborted)
Cannot create a connection to data source 'DS2'. (rsErrorOpeningConnection)
For more information about this error navigate to the report server on the local server machine, or enable remote errors
I'll add this from the report logs...
w3wp!processing!1!3/20/2007-11:43:25:: e ERROR: Data source €˜DS2€™: An error has occurred. Details: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Cannot create a connection to data source €˜DS2€™. ---> System.Data.SqlClient.SqlException: Cannot open database €œDatabase€? requested by the login. The login failed.
Login failed for user €˜DOMAINUsername€™.
The user has rights via a local group to the report and data source (Browser rights) and the local group has been added as a SQL login.
I gave rights to the databases themselves instead of just to SQL and the error changed (Ah-ha...progress, but why!?!?)
View 3 Replies
View Related
Oct 8, 2007
I had a function like below :Public Sub Getdata2(ByVal query, ByVal db, ByVal name)
Dim selectSQL As StringDim con As SqlConnection
Dim cmd As SqlCommand
Dim reader As SqlDataReader
Trycon = New SqlConnection("User ID=xxx;password=xxx;persist security info=True;Initial Catalog=database1;Data Source=xxx.xxx.xxx.xxx.xxx,xxxxx;")
Dim username As String
username = Request.QueryString("username")
selectSQL = "SET DATEFORMAT DMY;Insert into table1(hse_num, st_name, proj_name, unit_num, postal, n_postal, flr_area, flr_sf, flr_rate, flr_ra_sf, land_area, land_sf, land_rate, lnd_ra_sf, prop_code, cont_date, title, sisv_ref, r_date, rec_num, source, username, DGP, Remarks, Sub_Code, caveat, consider, age) select hse_num, st_name, proj_name, unit_num, postal, n_postal, flr_area, flr_sf, flr_rate, flr_ra_sf, land_area, land_sf, land_rate, lnd_ra_sf, prop_code, cont_date, title, sisv_ref, r_date, rec_num, source, '" & username & "', DGP, Remarks, Sub_Code, caveat, consider, age from [yyy.yyy.yyy.yyy,yyyy].database2.dbo.table2 where " & querycmd = New SqlCommand(selectSQL, con)
con.Open()
reader = cmd.ExecuteReader()
lbl.Text = selectSQLCatch ex As Exception
lbl.Text = ex.Message
Finally
If (Not con Is Nothing) Then
con.Close()
con.Dispose()
End If
End Try
End Sub
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
May i know that how do i retrieve data from [yyy.yyy.yyy.yyy,yyyy].database2.dbo.table2 due to diffrent server, diffrent UID and Password
View 1 Replies
View Related
Apr 7, 2007
Hi
If i use this code i cant get the data showed, it show nothing."SELECT COUNT(DogImageDate) AS Amount, DogImageDate, DogImageID FROM EnggaardImages WHERE DogImageDate NOT LIKE (SELECT TOP 1 DogImageDate FROM EnggaardImages ORDER BY DogImageDate DESC;) GROUP BY DogImageDate ORDER BY DogImageDate DESC;"
But if i use this code i get data showed"SELECT COUNT(DogImageDate) AS Amount, DogImageDate, DogImageID FROM EnggaardImages GROUP BY DogImageDate ORDER BY DogImageDate DESC;"
Then i get Images(6)Images(1)Images(1)
But i dont want the first to be showed, therefor i use the Select TOP 1, so i get a look like this
Images(1)Images(1)
But i cant get it to work.
View 2 Replies
View Related
Apr 18, 2007
As title...
If it is, what syntax should I refer to?
Regards,
Ricky.
View 3 Replies
View Related
Mar 27, 2006
I have created a sql login account called "webuser" and has given public role in my database. In my asp.net application i build connection string using above account and its password . We give permission on store procedure for for the above account to execute .We dont give table level permission for the above account . When we run the application with the above settings it runs fine on test server . However Now i have transfered the databse object to live server with its permissions . Now while I executing the aspx page , I am getting above error . I have checked that the store procedure has execute permission for webuser account and dbo(i.e SA) has all the permissions for all database objects . Still why i am getting error ? (Please note , the thing is working fine in test server)
Pl help
Regards
View 4 Replies
View Related
Jun 9, 2005
Not totally sure if this is the best place for this question, but regarding maintainability / good practice issues vs speed I have a question regarding what is the best way to SELECT some data from a database.I have the item_id of an item bought. I want to get a customer's billing information based on the item he bought. Should I do this with two queries or one using joins?
Here is my dbase schema:
customer_info--------------customer_idnamecc_numexpdate
item_bought------------item_idcustomer_id
And here is a basic pseudocode algorithm:function getCustomerInfo(customerID){ SELECT customer_info.name, customer_info.cc_num, customer_info.expdate FROM customer_info WHERE customer_id=customerID; return results;}
function getCustomerInfoWithItemId(itemID){ SELECT item_bought.customer_id FROM item_bought WHERE item_bought.item_id=itemID; results = getCustomerInfo(customer_Id);
return results;}
results = getCustomerInfoWithItemId(400);OR
function getCustomerInfoWithItemId(itemID){ SELECT customer_info.name, customer_info.cc_num, customer_info.expdate FROM customer_info, item_bought WHERE item_bought.item_id=itemIDAND customer_info.customer_id = item_bought.customer_id; return results;}
results = getCustomerInfoWithItemId(400);
View 7 Replies
View Related
Oct 19, 2001
When I run this query:
select * into database2.UserX.Table1 from database1.dbo.Table1
I get the following error:
Server: Msg 268, Level 16, State 3, Line 1
Cannot run SELECT INTO in this database. The database owner must run sp_dboption to enable this option.
when I change the db option to 'dbo use only' 'false' ,still I get the same error.How to run the above statement?
View 1 Replies
View Related
Jul 12, 2007
Hi,
I've been having some trouble finding the correct syntax for the following query, where I am simply trying to move selected records from table A in database A to table A in database B.
Here is what I have:
Code:
SELECT pd.phoneID, phonebookID, timezoneID, phoneNumber, lastName, firstName, address, city, state, country, zip, custom, custom2, custom3, memo, fax, email
INTO history.set_appointment1
FROM pro_PhoneData pd
LEFT JOIN pro_Campaign_1_Results cr ON pd.phoneID = cr.phoneID
WHERE ((phonebookID='3') OR (phonebookID='1'))
AND descriptionID = '203'
AND callTime < GETDATE()-365
ORDER BY callTime DESC
When I execute this query, I get the following message: "The specified schema name "history" either does not exist or you do not have permission to use it."
I've looked up examples for select into queries and have played around with it a bit, but no such luck.
Anyone have a solution?
Thanks!
View 2 Replies
View Related
Mar 23, 2008
Here's my table:
--------------------------
Teams
--------------------------
ID | Name | City | State
--------------------------
I want to output the Teams in this format:
Name
City, State
However, some teams don't have a name, so I want to output them like this:
City, State Team
City, State
And some teams don't have a name or a city:
State Team
State
And then there are teams who have a name, but not a city:
Name
State
I'd like to do this all in one select statement. Is there a way to do something like:
SELECT Name IF EXISTS, City IF EXISTS, State IF EXISTS
FROM TEAMS
View 5 Replies
View Related
Oct 24, 2005
my table ha follow structure..SalaryTable:Value Salary------------Jan 1000Feb 2000Mar 3000Apr 4000i want the o/p as..Jan Feb Mar Apr1000 2000 3000 4000Pls give me a query for thisRegards,Satheesh
View 1 Replies
View Related
Sep 27, 2006
Hello!
I am trying
to select info from a database (MS-SQL) and show that whit a label. And don’t really
get every thing to work. So I am glad for that help I can get.
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "data
source='XXX';User ID='XXX';Password=XXX;database='XXX'";
myConnection.Open();
SqlCommand dataCommand = new
SqlCommand();
dataCommand.Connection
= myConnection;
dataCommand.CommandText = "SELECT XXX,XXX FROM XXX";
SqlDataReader dataReader =
dataCommand.ExecuteReader();
string notis1 = dataReader;
Label1.Text = notis1;
myConnection.Close(); Any help whould be helpfoul.
View 5 Replies
View Related
May 18, 2007
I have a single form that the users can do lookups for items. We have two locations each with its own SQL Server and database. Trying to use an IF...THEN statement as they select the DB they want to query it then creates the connection string for that particular database. I haven't a clue on how to do this. If someone could point me to the documentation to do this I would really appreciate it. <%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub get_Dies(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim dbConnection As New SqlConnection
If ddlDatabase.SelectedValue = "db2" Then
??? dbConnection = "server=server2;Database=db2;UID=user;PWD=pass"
dbConnection.Open()
Else
??? dbConnection = "server=server1;Database=db1;UID=user;PWD=pass"
dbConnection.Open()
End If
Dim sqlString As String = " sql statement"
Dim dbCommand As New SqlCommand(sqlString, dbConnection)
Dim dbDataReader As SqlDataReader
dbDataReader = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)
gvDies.DataSource = dbDataReader
gvDies.DataBind()
dbConnection.Close()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Die Usage Lookup</title>
<link rel="stylesheet" href="/intranet.css" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
Find dies matching:
<asp:TextBox ID="tbDies" runat="server" /><br />
Select database:
<asp:DropDownList id="ddlDatabase" runat="server" AutoPostBack="true" OnSelectedIndexChanged="get_Dies">
<asp:ListItem Text="" Selected="true" Value="" />
<asp:ListItem Text="DB1" Value="db1" />
<asp:ListItem Text="DB2" Value="db2" />
</asp:DropDownList>
<asp:gridview ID="gvDies" runat="server" GridLines="none" >
</asp:gridview>
</div>
</form>
</body>
</html>
View 2 Replies
View Related
Jan 31, 2005
Is it possible to select the available space of the database in a microsoft sql MSDE edition?
With sysfiles i can see the size of the database but where can i find the available space or the used space of the database.
View 2 Replies
View Related
Mar 2, 2006
Hello...
I am using SQL Server Express and ASP.net with C#
I need to grab a value from a table in database1 and insert it into a table in database2... not quite sure how to do this?
Any ideas???
Thanks muchos!
View 11 Replies
View Related
Jul 31, 2007
Hi how do I select the current logical database name using a select statement.
View 8 Replies
View Related
Nov 20, 2007
Hi,
I have a problem during my etl process. my customer do not want that everytime the ssis package running, the dw table been cleen up/delete all. so i just have to process only with the new data. For example is like this:
Source Database: db1
Table DataEmp
id name address
----------------------------
1 Mike California
2 David New York
3 Bruce Ohio
Destination Database: db2
Table DimDataEmp
DataEmpKey DataEmpName DataEmpAddress
----------------------------------------------------------------------
1 Mike California
2 David New York
My goal now is, if i run the ssis package the only data transfer is (3, Bruce, Ohio). how am i do it? i already try the merge, merge join, or lookup control, but still don't work. basically i want to "select not exist" the destination table but in different database. please help me, cos i still new in ssis. Thanks
Sincerely Yours,
Yugi
View 3 Replies
View Related
Jul 14, 2007
I have a table "tbNews" in my database with N_ID, N_Content...
eg:
N_ID N_Content
1 Hello
3 How are you?
14 Are you there?
23 Can you help me?
32 ABC
33 CDE
36 EFG
If I have my N_ID = n (with n=1,3...) , can I select my records with next 1,2 or pre 1,2
eg: I have my N_ID=23, -->can I have got N_ID=3, 14 or N_ID=32, 33 ?
N_ID N_Content
3 How are you?
14 Are you there?
or
32 ABC
33 CDE
Please help me have a Select clause!
Thanhs all.
View 3 Replies
View Related
Mar 24, 2008
select * from tbl where nmonth between datepart(mm,DATEADD(month, -2, getdate())) and datepart(mm,getdate())
this query is returning my data between 1(jan) and 3 (mar)
if i change my query to get all datas between nov to mar
select * from tbl where nmonth between datepart(mm,DATEADD(month, -4, getdate())) and datepart(mm,getdate())
this query is not returning data since the month between 11 to 3
Guys,Help me out to correct this syntax.
View 4 Replies
View Related
Jun 13, 2006
Hi!
Anyone knows how to select
only certain data from one data field?
Lets say i have this field which captures
Member Name and ID.
The ID is in parantheses "()".
I only want the Member name.
How do I select this from the table?
E.G.:
Field: Data
MName: John Doe (123)
I need to select only "John Doe".
Any help is deeply appreciated.
Thank you!!
View 1 Replies
View Related
Jun 26, 2001
Hi, and tanks for taking time to read this question. I am still a novice at SQL (Server 2000)programming.
Is there a way to replace the contents of a column of a table derivied from SELECT and WHERE statements?
For example,
SELECT * FROM table1
WHERE column1 = 'text'
and replace 'text' with say, 'newtext'
Any help would be appreciated!
Regards,
Chandran
View 5 Replies
View Related
Sep 8, 2004
I'm really in need of help with this one!!
I am writing a script which will provide me with financial info.
This will then be used to upload to a management system.
I have tried using the following code;
select
year.mem_desc as year,
line.mem_name as line,
unit.mem_name as unit,
ver.mem_name,
version =
Case
when ver.mem_name like 'Actual' then 'Actual Input'
when ver.mem_name like 'Forecast' then 'Actual Input'
when ver.mem_name not like 'Actual' then ver.mem_name
end,
cust1.mem_name as product,
cust2.mem_name as costcentre,
cust3.mem_name geographic_market,
cust4.mem_name as segment,
Jan =
case
when Jan is null and ver.mem_name like 'Actual'
then select Jan from finloc where year.mem_desc like year and line.mem_name like line and
unit.mem_name like unit and ver.mem_name like 'Forecast'
when ver.mem_name like 'Forecast'
then select Jan from finloc where year.mem_desc like year and line.mem_name like line and
unit.mem_name like unit and ver.mem_name like 'Actual'
when Jan is not null then convert(varchar(50),Jan)
end,
This doesnt work!! I need to be able to say that if the columns are blank or null for Actual then take Forecast, a kind of merge statement is needed but I dont know how to write one, can someone please please help!!
View 2 Replies
View Related