Select No. Of Rows From The Current Database

Jul 19, 2006

Hello,
I want to select the names and number of rows of all tables in the
current database, whose name starts with 'sys'
my query is:

select o.[name], sum(i.[rows]) as numbers
from sysobjects o
inner join sysindexes i
on (o.[id] = i.[id])
where o.[name] like 'sys%'and i.indid=1
group by o.[name]


the result of the query is (depending of the database) :


name numbers
sysaltfiles 14
syscharsets 114
syscolumns 4934
syscomments 2035
sysconfigures 38
sysdatabases 7
sysdepends 5524
sysdevices 6
sysfilegroups 1
sysfulltextcatalogs 0
sysfulltextnotify 0
sysindexes 98
syslanguages 33
sysmessages 3795
sysobjects 1285
syspermissions 806
sysproperties 0
sysreferences 0
sysservers 1
systypes 26
sysusers 14
sysxlogins 3


But when I count the number of rows of "sysobjects", I get
numbers=1298, which is different from the result displayed above and
same goes for "syscolumns".
I also tried "dbcc updateusage [0]" to update the SQL Server but I
didnt help me.
Can anyone please advice me on this behaviour?

View 2 Replies


ADVERTISEMENT

Get Rows Between Current Date And Current Time

Jun 8, 2008

I've this query
SELECT
t1.ID, t1.Date, t1.Time,
t1.VALUE
FROM RESULT WHERE t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101)

Let's say, current date is 8 AUG 2005 and current time is 2045
So, i will get
ID | Date (this is datetime) | Time (this is integer) | Value
--------------------------------------------------
204 | 8/1/2005| 2359 | 90
205 | 8/1/2005| 2250 | 99
206 | 8/1/2005| 1950 | 88
...
...
207 | 8/7/2005| 1845 | 77
208 | 8/7/2005| 2255 | 77
209 | 8/7/2005| 2140 | 77

Can someone can show me to filter data between
t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND TIME>=CurrentTime
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101) AND TIME<=CurrentTime

If current date is 8 AUG 2005 and current time is 2045, so the result shown as follow

ID | Date (this is datetime) | Time (this is integer) | Value
--------------------------------------------------
204 | 8/1/2005| 2359 | 90
205 | 8/1/2005| 2250 | 99
...
...
207 | 8/7/2005| 1845 | 77

I only have this query,
SELECT
t1.ID, t1.Date, t1.Time,
t1.VALUE
FROM RESULT WHERE t1.Date>=CONVERT(VARCHAR(10),DATEADD(d,-7,GETDATE()),101) AND
t1.Date<CONVERT(VARCHAR(10), GETDATE(), 101)

lack of idea to put the TIME condition.

Plz help me..

View 14 Replies View Related

How Can Select Random Rows From Database?

Jan 23, 2008

Hi
Iam developing online test using ASP.NET,C#.NET.Now my doubt is test takers should get random questions from the database sqlserver2005.Already i ve inserted 10 question into the database.I ve used NEW ID() .But questions are repeating.I am new commer in to IT industry .Provide me with code.Given below is my code.I can retrive questions from the database now but cannot get in random order.protected void Page_Load(object sender, EventArgs e)
{Label10.Visible = false;
Label9.Visible = false;if (!IsPostBack)
{if (Session["id"] == null)
{Session["id"] = 1;
}Session["ans"] = 0;SqlConnection con = new SqlConnection(@"server=123-9181FF31362SQLEXPRESS;user id=sampleu;pwd=Sampleu2;database=n;");
con.Open();
SqlCommand cmd = new SqlCommand("select * from n3 where sno='" + Convert.ToInt16(Session["id"].ToString()) + "' ", con);SqlDataReader re;
re = cmd.ExecuteReader();while (re.Read())
{
 
Label1.Text = re[0].ToString();
Label2.Text = re[1].ToString();
Label3.Text = re[2].ToString();
Label4.Text = re[3].ToString();
Label5.Text = re[4].ToString();
Label6.Text = re[5].ToString();string sss = re[6].ToString();if (sss == "nil")
{
Panel1.Visible = true;Panel2.Visible = false;
}
else
{Panel1.Visible = false;Panel2.Visible = true;
}
}
re.Close();
}
}
 
 protected void Button1_Click(object sender, EventArgs e)
{string Answer = "";if (RadioButton1.Checked == true)
{Answer = "A";
}else if (RadioButton2.Checked == true)
{Answer = "B";
}else if (RadioButton3.Checked == true)
{Answer = "C";
}else if (RadioButton4.Checked == true)
{Answer = "D";
}else if (RadioButton5.Checked == true)
{Answer = "True";
}else if (RadioButton6.Checked == true)
{Answer = "False";
}SqlConnection con1 = new SqlConnection(@"server=123-9181FF31362SQLEXPRESS;user id=sampleu;pwd=Sampleu2;database=n;");
con1.Open();
string ss = Session["id"].ToString();SqlCommand cmd1 = new SqlCommand("select Answer from n3 where sno='" + Convert.ToInt16(Session["id"].ToString()) + "' ", con1);
SqlDataReader re1;string result1 = "";
re1 = cmd1.ExecuteReader();if (re1.Read())
{
result1 = re1[0].ToString();
}
//Session["ans"] = 0;if (Answer == result1)
{Session["ans"] = (Convert.ToInt16(Session["ans"].ToString()) + 1);
 
}
con1.Close();
 Session["id"] = (Convert.ToInt16(Session["id"]) + 1);
RadioButton1.Checked = false;RadioButton2.Checked = false;
RadioButton3.Checked = false;RadioButton4.Checked = false;
RadioButton5.Checked = false;RadioButton6.Checked = false;
 
 SqlConnection con = new SqlConnection(@"server=123-9181FF31362SQLEXPRESS;user id=sampleu;pwd=Sampleu2;database=n;");
con.Open();SqlCommand cmd = new SqlCommand("select * from n3 where sno='" + Convert.ToInt16(Session["id"].ToString()) + "' ", con);SqlDataReader re;
re = cmd.ExecuteReader();
 
 
 while (re.Read())
{
Label1.Text = re[0].ToString();
Label2.Text = re[1].ToString();
Label3.Text = re[2].ToString();
Label4.Text = re[3].ToString();
Label5.Text = re[4].ToString();
Label6.Text = re[5].ToString();string sss = re[6].ToString();if (sss == "nil")
{
Panel1.Visible = true;Panel2.Visible = false;
}
else
{Panel1.Visible = false;Panel2.Visible = true;
}
}
re.Close();int s = Convert.ToInt16(Session["id"].ToString());if (s == 11)
{
Label10.Text = Session["ans"].ToString() + " / " + "10";Label9.Visible = true;
Label10.Visible = true;
//int x = Convert.ToInt16(Session["ans"].ToString());
//int y = (x/10) * 100;//y = Label10.Text;
 
}
////// SqlConnection con6 = new SqlConnection(@"server=123-9181FF31362SQLEXPRESS;user id=sampleu;pwd=Sampleu2;database=n;");
////// con6.Open();
////// SqlCommand cmd6 = new SqlCommand("SELECT CONVERT(int, 10*RAND()) from n3 where sno='" + Convert.ToInt16(Session["id"].ToString()) + "' ", con6);
////// SqlDataReader re6;
////// re6 = cmd6.ExecuteReader();
////// //select top 5 * from Employee order by NEWID()
//////// SELECT FirstName,LastName
////////FROM Person.Contact
////////TABLESAMPLE SYSTEM (10 PERCENT)
 
////// while (re6.Read())
////// {
////// Label1.Text = re6[0].ToString();
////// }
////// con6.Close();
}
}

View 3 Replies View Related

Select Rows From Another Server's Database

Jun 2, 2003

Hi,

I need to import data from another server on recurring basis. Before inserting the data, I need to perform some checking e.g. check the last update date and time.

I am thinking of scheduling SQL job that run SQL Query. The SQL query will make use of cursor to check each row, to decide what to do with the imported data

Is it the right way to import the data? However I did not know how to select data from another server using T-SQL. Can help? I am using SQL 2000

Thanks in advance

Regards,
Christine

View 8 Replies View Related

Select Rows From Database Where Fields Are Null

Dec 30, 2006

Hi, how do i do a select statement with asp.net to return a record if a field is null.  I have the following code:
SqlCommand cmd = new SqlCommand("SELECT * FROM Categories WHERE ParentId = @ParentId", cn);.Parameters.Add("@ParentId", SqlDbType.Int).Value = parentId != null ? (object) parentId : DBNull.Value;cn.Open();
The variable parentId is a nullable int.  However when i pass in a null value it doesn't return anything even though there are records in the database that have a null value for the ParentId field.
Appreciate if someone could tell me what i am doing wrong.  Thanks

View 6 Replies View Related

Fetching Next Previous And Current Rows?

May 19, 2012

I am trying to create a stored procedure where i would like to fetch the next previous and current rows from a particular pagename which is stored in a table with sorting of dateadded

like my products table structure

id
iQty
strProductTitle
strPageName
DtAdded
DtApproved

my dummy records are like

1 13 'PCHDD' 'PCHDD' '2009-12-03 04:32:30.363' '2009-12-04 04:32:30.363'
2 30 'SDRAM' 'SD_Ram' '2009-12-03 04:32:30.363' '2009-12-06 04:32:30.363'
3 12 'Pen Drive' 'Pendrive' '2009-12-03 04:32:30.363' '2009-12-05 04:32:30.363'
4 3 'Note Book' 'NoteBook' '2009-12-03 04:32:30.363' '2009-12-08 04:32:30.363'
5 15 'VIO' 'VIO' '2009-12-03 04:32:30.363' '2009-12-06 04:32:30.363'
6 19 'PS2' 'PS_2' '2009-12-03 04:32:30.363' '2009-12-09 04:32:30.363'
7 31 'PS3' 'PS_3' '2009-12-03 04:32:30.363' '2009-12-02 04:32:30.363'
8 23 'WII' 'WII' '2009-12-03 04:32:30.363' '2009-12-10 04:32:30.363'
9 22 'Speakers' 'Speakers' '2009-12-03 04:32:30.363' '2009-12-16 04:32:30.363'
10 12 'Iphone' 'I_phone' '2009-12-03 04:32:30.363' '2009-12-15 04:32:30.363'

now if i query for a record like

I_phone
i should get
Prv Detail I_pad row
11 23 'Ipad' 'I_pad' '2009-12-03 04:32:30.363' '2009-12-11 04:32:30.363'
Current Detail I_phone
10 12 'Iphone' 'I_phone' '2009-12-03 04:32:30.363' '2009-12-15 04:32:30.363'
Next Record Speakers
9 22 'Speakers' 'Speakers' '2009-12-03 04:32:30.363' '2009-12-16 04:32:30.363'

View 2 Replies View Related

T-SQL (SS2K8) :: Get Rows Based On Current Quarter

Sep 3, 2014

I am working on a report and the data source is Teradata. now I have situation where I want to get order id details based on the current quarter and year I am posting this same data. For TD related queries I do not where to post.

ACCT_ID ACCT_NMORD_NBRORD_DT ORD_AMT_USD
595709114ASDASD444447/28/2014 546
2224809440ASDASD444445/2/2012 546
1724031572ASDASD444446/22/2011 546
1702887651ASDASD444447/3/2014 546
1724020508ASDASD444447/16/2012 546
1148151895ASDASD444449/18/2013 546
2125154824ASDASD444449/2/2014 546
1503552723ASDASD4444412/20/2011 546
2224689808ASDASD4444410/4/2010 546
931387698ASDASD4444412/31/2010 546

View 4 Replies View Related

SQL Error: 16931 (There Are No Rows In The Current Fetch Buffer)

Sep 15, 2007


Hi,

I am having problem with the CRecorset::Update() function.
I have declared a CRecordset object in client Application in VC++6.0.
I open the recordset in dynamic mode.
Before opening the recordset , I have obtained the UPDLOCK on the base table.( Obviously this UPDLOCK is in transaction).
When I try to call CRecordset::Update() it gives me exception 16931(There are no rows in the current fetch buffer).
I have define a clustered index on this table.
But I still get the exception 16931 on calling CRecorset::Update().

Any help is much appreciated.
Thanks in advance.

View 2 Replies View Related

Lookup Current Id In Kimball Type II Dimension For Fact Rows

May 8, 2007

Hi all,



Maybe someone here can help me out: I have a Kimball type II dimension, where i track changes in a hierarchy. Each row has a RowStartDate and RowEndDate property to indicate from when to when a certain row should be used.



Now i want to load facts to that table. So each fact will have a certain date associated with it that i can use to lookup the right Id (a certain SourceId can have mulitiple integer Ids when there are historic changes) and then load the facts.



Is there a building block I can use for that? I could do this with SQL scripts but the client would prefer to have as much as possible done in SSIS. The Lookup transformation will only let me specify an equal (inner join where A=B) join, but i need equal for one column (SourceId) and then >= and <= (RowStart and RowEnd) to find the right row version.



Any ideas? Thanks in advance,



John

View 3 Replies View Related

Select Current Year ?

Mar 30, 2006

what is the query to find

current year
current month
current day
using sql query analyser

View 4 Replies View Related

Using A Current Row Value In A Nested Select

Jun 3, 2007

I have two tables:

1)table of customers: CustomerName, CustomerId, CustomerAddress
2)table of orders: OrderId, CustomerId, OrderAmount

I would like to have a query that returns everything from the customer table and add one column that has the amount of orders the customer has made, this is what I have so far:

CREATE PROCEDURE dbo.GetAllCutomerInfo
AS

DECLARE @OrderCount int

SELECT CustomerName, CustomerId, CustomerAddress, (SELECT COUNT(OrderId) FROM Cust_Orders WHERE CustomerId= CustomerId)
FROM Customers
ORDER BY CustomerName


Can you add a variable:

CREATE PROCEDURE dbo.GetAllCutomerInfo
AS

DECLARE @CustID int

DECLARE @OrderCount int

SELECT CustomerName, @CustID=CustomerId, CustomerAddress, (SELECT COUNT(OrderId) FROM Cust_Orders WHERE CustomerId= @CustID)
FROM Customers
ORDER BY CustomerName


Thanks for any help.

View 4 Replies View Related

Select 'Current LSN' And 'Transaction ID' From ::fn_dblog

Mar 23, 2006

Gurus,How do I choose multi-name 'columns' like "Current LSN" or "TransactionID" from ::fn_dblog?I CAN select single 'column' names like 'Operation' and 'Context'.I do NOT want all 'columns' returned:- I don't want Select (*) from ::fn_dblogDoug

View 2 Replies View Related

Select Records For The Current Logged On User

May 14, 2007

Hi all
I've been having a really difficult time finding out how to run a query which selects records from an SQL database for the current logged on user. I've tried a whole manner of different approaches but here is where I am at now:
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
ds_meobservingcolleagues.SelectParameters(0).DefaultValue = User.Identity.Name
End If
End Sub
</script>
 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ds_meobservingcolleagues">
</asp:GridView>
<asp:SqlDataSource ID="ds_meobservingcolleagues" runat="server" ConnectionString="<%$ ConnectionStrings:StPaulsDatabase %>"
SelectCommand="SELECT [observeTeacher], [observeBy], [observeReason] FROM [Observations] WHERE ([observeBy] = @observeBy)">
<SelectParameters>
<asp:Parameter Name="observeBy" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
 
This is not resulting in any error. But it is not returning the records that it should be either.
Please can anyone help? I'm sure it shouldn't be this difficult to do

View 3 Replies View Related

How To Select Current Client IP Address Using T-SQL Command ?

Jul 4, 2006

I have problem to find Current IP address for client computer that have a connection to Specific DataBase Server .I can only know the IP Address of DataBase Server but not current client user IP address that I am seeking to find it
,How can I do this by using T-SQL command?
Please write full T-SQL code .

View 2 Replies View Related

DataSet Rows Being Deleted, But After The Update , The Sql Database Is Not Updated. The Delete Rows Still In The Database.

Jun 4, 2007

 Stepping thru the code with the debugger shows the dataset rows being deleted.
 
After executing the code, and getting to the page presentation. Then I stop the debug and start the
page creation process again ( Page_Load ).    The database still has the original deleted dataset rows.
Adding rows works, then updating works fine, but deleting rows, does not seem to work.
 
The dataset is configured to send the DataSet updates to the database. Use the standard wizard to create the dataSet.
 
 
cDependChildTA.Fill(cDependChildDs._ClientDependentChild, UserId);        rowCountDb = cDependChildDs._ClientDependentChild.Count;               for (row = 0; row < rowCountDb; row++)        {           dr_dependentChild = cDependChildDs._ClientDependentChild.Rows[0];           dr_dependentChild.Delete();                      //cDependChildDs._ClientDependentChild.Rows.RemoveAt(0);           //cDependChildDs._ClientDependentChild.Rows.Remove(0);            /* update the Client Process Table Adapter*/          // cDependChildTA.Update(cDependChildDs._ClientDependentChild);      //     cDependChildTA.Update(cDependChildDs._ClientDependentChild);        }
        /* zero rows in the DataSet at this point */        /* update the Child  Table Adapter */       cDependChildTA.Update(cDependChildDs._ClientDependentChild);

View 1 Replies View Related

SELECT From DateTime Field Based On Current Date

Feb 5, 2008

I am trying to match records that are >= the current date. I have tried using:
SELECT DISTINCT name
FROM table
WHERE datefield >= DATEPART(month, GETDATE()) AND datefield >= DATEPART(day, GETDATE()) AND datefield >= DATEPART(year, GETDATE())
ORDER BY name
but this is not giving me the result that I am looking for. What is the best way to match a DateTime field type using the current date without the time?

View 5 Replies View Related

Select Statement To Return Most Current Syscreated Date On Duplicates

Jun 29, 2006

I have a db that has duplicate customer records.

If I run the following select statment against the appropriate table it returns the duplilcate records in the result set. However, from this list I want to add an additional select statement embedded into the query that will actually return only those records with the most current syscreated date.

Example of script I'm using---

select cmp_fadd1, syscreated, cmp_name, cmp_code
from cicmpy
where cmp_fadd1 in (select cmp_fadd1
from cicmpy
group by cmp_fadd1
having count(1) = 2)
order by cmp_fadd1,syscreated desc

The results is:

Address Syscreated date Customer
1622 ONTARIO AVENUE 2005-06-15 22:19:45.000 RELIABLE PARTSLTD
1622 ONTARIO AVENUE 2004-01-22 18:10:05.000 RELIABLE PARTS LTD
PEI CENTER 2006-01-05 22:03:50.000 P.G. ENERGY
PEI CENTER 2004-01-22 17:57:56.000 P.G. ENERGY

From this I want to be able to select ONLY those records with the most current syscreated date or those records with 2005-06-15 and 2006-01-05

Can anyone help me with creating this?

Thanks

Cyndie

View 4 Replies View Related

Select Distinct Rows From Duplicate Rows....

Nov 28, 2007

Dear Gurus,I have table with following entriesTable name = CustomerName Weight------------ -----------Sanjeev 85Sanjeev 75Rajeev 80Rajeev 45Sandy 35Sandy 30Harry 15Harry 45I need a output as followName Weight------------ -----------Sanjeev 85Rajeev 80Sandy 30Harry 45ORName Weight------------ -----------Sanjeev 75Rajeev 45Sandy 35Harry 15i.e. only distinct Name should display with only one value of Weight.I tried with 'group by' on Name column but it shows me all rows.Could anyone help me for above.Thanking in Advance.RegardsSanjeevJoin Bytes!

View 4 Replies View Related

The Database Name Component Of The Object Qualifier Must Be The Name Of The Current Database

Apr 7, 2006

Guys,1st of all.. sorry about my english ok? Im from Brazil...Im trying to get a RS connecting through 2 databases with the querybelow:SELECTscar..osbalcao.numeroos,ccell.dbo.atrib_os.osFROMccell.dbo.atrib_osJOIN scar.dbo.osbalcao on ccell.dbo.atrib_os.os =scar.dbo.osbalcao.numeroosWHERE scar.dbo.osbalcao.localprod = '257'AND scar.dbo.osbalcao.status in ('EM')On a SQL IDE i got a good RS, but, when i try to use that same query onDelphi + ZEOS, the SQL Server tells me that "The database namecomponent of the object qualifier must be the name of the currentdatabase".I really dont understand why. I can only tell that the error isreturned from SQL Server.Have anyone got the same trouble?[]'sTiago Gigli

View 1 Replies View Related

SELECT * Not Returning Any Rows, But SELECT COL_NAME Does!

Jul 20, 2005

I have a table which is returning inconsistent results when I queryit!In query analyzer:If I do "SELECT * FROM TABLE_NAME" I get no rows returned.If I do "SELECT COL1, COL2 FROM TABLE_NAME" I get 4 rows returned.In Enterprise manager:If I do "return all rows" I get 4 rows returned, and the SQL is listedas being "SELECT * FROM dbo.TABLE_NAME".I've tried adding the "dbo." before my table name in QA, but it seemsto make no difference.I'm using SQL Server 2000, which is apparently 8.00534.Can anyone help me, or give me ideas about what to check?Thanks,Rowland.

View 9 Replies View Related

Accessing Tables Of A Different Database From The Current Database

Apr 15, 2008



Hi,

In a stored procedure is there a way of accessing a table presend in another database.

Please provide pointers on how i can do this.

Thanks,
Raj

View 4 Replies View Related

Acessing Tables Of Different Database From Current Database

Apr 15, 2008

Hi,

In a stored procedure is there a way of accessing a table present in another database.

Please provide pointers on how i can do this.

Thanks,
Raj

View 4 Replies View Related

Current Database

Oct 19, 1999

Hi,

Is there any command that gives the current database name.

Regards
Kishore

View 1 Replies View Related

How To Get Current Database Name?

Aug 4, 2006

How to get current database name using stored procedure?

View 2 Replies View Related

Current Database Name...

Mar 26, 2004

Hi,
I want to know a sql query that would show the current database name.
I have tried looking into the online books but couldn't find the right query.I hope u can do better.This is urgent.Thanxs. -- Vijay

View 2 Replies View Related

Current Database Name Needed...

Apr 10, 2002

Hi:

I need to know the current database name in executing a stored procedure,
which will trancatte the log of that database.
(in a dynamic multiple customerID oriented database environment,
ex. custID_101_db, custID_102_db, .....)

View 1 Replies View Related

Selecting Current Database

Apr 27, 2007

Hello,

When I open a query analyzer , of a particular database for example 'AB'

when writting a query how can I get the databasename that I am executing

i.e in the result I should get the DB name.

I was trying select name from master..sysdatabases . But it was returning all DB names.

Also while running a query , can I prompt for the DB name , so that that particular db name can be used to run that procedure or query.

Thanks in advance

View 2 Replies View Related

Check Current Database

Jun 18, 2007

I was wondering if it was possible to check what server database you are currently connected to, using T-SQL, when executing commands in Query Analyzer. Even though you choose the server and database when connection, sometimes by habit you may connect to the wrong server & DB, and execute an .SQL file. Is it possible to put a line of T-SQL at the beginning that performs this pseudo-code, as a safety feature:-- While in Query Analyzer with a certain .SQL file open:If current server <> 'TheCorrectServer' and current DB <> 'TheCorrectDB' then cancel this .SQL file execution.

View 3 Replies View Related

Can Alter (current) Database?

Apr 7, 2006

I have a *.sql script that creates database tables, and I need to modify the database to enable the service broker. In addition, the actual name of the database is not known in advance - it is set per instance of the application.

I know I need to do:

ALTER DATABASE dbname SET ENABLE_BROKER

But I must avoid including the name of the database in the script. I did wonder if this would work:

DECLARE @DB varchar(50)

SELECT @DB = DB_NAME()

ALTER DATABASE @DB SET ENABLE_BROKER

But I just get a syntax error. Presumably this also rules out setting the database name as a parameter to the script (SqlParameter stuff)

The only option I can think of is dynamically creating the statement, either in T-SQL or in the calling .NET environment.

Any thoughts?

Ruth

View 6 Replies View Related

The Target Is Not In The Current Database

May 18, 2007

Can someone please help me with the following error?



I am trying to create a trigger that copies data from a table in one database to another. However I am getting the error 'Cannot create trigger on databasename.dbo.tablename as the target is not in the current database.



Below is the SQL I am using to create the trigger:

create trigger addtotable1

on databasename.dbo.tablename

for insert

as

insert into anotherdatabase.dbo.tablename

select databasename.dbo.tablename.userid, databasename.dbo.tablename.username, biadatabasename.dbo.tablename.issuperuser

from databasename.dbo.tablename, inserted

where databasename.dbo.tablename.userid = inserted.userid

and inserted.roleid = 3



Andrew Ling

View 8 Replies View Related

Database Query Won't Use Current Date

Mar 11, 2008

Hi, I've just started using SQL Server Express with VWDE 2005 and I have a database with one table called EVENTS which has a datetime column called DATE. I want to select records where the DATE value is in the next two months.First I tried selecting records where the DATE value is >= today. I used the query builder to produce... SELECT [Date], [Title] FROM [Events] WHERE [Date] >= GETDATE()but got the error "Undefined function 'GETDATE' in expression".Am I missing something obvious? 

View 5 Replies View Related

Other Way Of Setting Current Database In SQL Script

Nov 7, 2001

Hi,
I'm trying to create an SQL script that creates a new login account for each of our databases. The one remaining problem with the sql is it could not set the current database using a variable(e.g. USE @dbasename). I tried looking for another way of setting the current database but could not find one.

Is there any other way of setting the current database other than the USE command?

Any help/suggestion will be appreciated.

Thanks in advance,
Julius

View 1 Replies View Related

Quick Question: How Do I Get The Name Of The Current Database?

Jul 23, 2005

Is there an sp_zzzzzz function to return the name of the current database?I would like to use this name as a variable in a stored procedure in orderto create names for further databases (by appending a tag, such asMYDATABASE_BLOB001, ..._BLOB002 etc.Thanks.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved