How To Check Other DB's Table

Sep 6, 2005

Hi,I have two databases called DB1 and DB2. DB1 has a table called table1 and DB2 has table2.I want to write one SP into the DB1, that SP will check whether table2 into the DB2 is exists or not, how do I do it? Any help?I know if it is into the same database then,IF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = object_id(N'[table2]') and OBJECTPROPERTY(ID, N'IsTable') = 1)-- then do some thingI tried replacing "dbo.sysobjects" with "DB2.dbo.sysobjects", but no luck.Any Help???

View 2 Replies


ADVERTISEMENT

How To Do-table 1 That Check Table 2 And Adding Missing Dates

Dec 20, 2007

can sql server do this ?
table 1 that check table 2 and adding missing dates
this my employee table

table 1
table Employee on work
------------------------
empid basedate shift
----------------------------
12345678 01/04/2007 1
12345678 02/04/2007 1
12345678 03/04/2007 1
12345678 04/04/2007 1
12345678 05/04/2007 1
12345678 06/04/2007 1
12345678 07/04/2007 1
12345678 08/04/2007 1
12345678 09/04/2007 1
12345678 10/04/2007 1

98765432 20/04/2007 1
98765432 21/04/2007 3
98765432 22/04/2007 3
98765432 23/04/2007 5
98765432 25/04/2007 4
98765432 26/04/2007 4
98765432 27/04/2007 4
98765432 28/04/2007 4
98765432 30/04/2007 4
-----------------------------------------------------------------------------------
and i need to see the missing dates lkie this

in table 2
------------------------------------------------------
table 2 (adding missing dates with zero 0)
table Employee_all_month
------------------------
empid basedate shift
----------------------------
12345678 01/04/2007 1
12345678 02/04/2007 1
12345678 03/04/2007 1
12345678 04/04/2007 1
12345678 05/04/2007 1
12345678 06/04/2007 1
12345678 07/04/2007 1
12345678 08/04/2007 1
12345678 09/04/2007 1
12345678 10/04/2007 1
12345678 11/04/2007 0
12345678 12/04/2007 0
12345678 13/04/2007 0
12345678 14/04/2007 0
12345678 15/04/2007 0
12345678 16/04/2007 0
12345678 17/04/2007 0
12345678 18/04/2007 0
12345678 19/04/2007 0
12345678 20/04/2007 0
.................................and adding missing dates with zero 0 until the end of the month
.................................
12345678 31/04/2007 0


98765432 01/04/2007 0
98765432 02/04/2007 0
98765432 03/04/2007 0
98765432 04/04/2007 0
98765432 05/04/2007 0
98765432 06/04/2007 0
98765432 07/04/2007 0
98765432 08/04/2007 0
98765432 09/04/2007 0
..............................and adding missing dates with zero 0 only whre no dates in this month
.......................

98765432 20/04/2007 1
98765432 21/04/2007 3
98765432 22/04/2007 3
98765432 23/04/2007 5
98765432 25/04/2007 4
98765432 26/04/2007 4
98765432 27/04/2007 4
98765432 28/04/2007 4
98765432 30/04/2007 4


TNX


View 4 Replies View Related

Check Id Exists In Sql Table?

Jan 17, 2008

Hi all,I am in the process of creating a page that checks to see if a particular user exists in the database and if it does then send to welcome.aspx if not then accessdenied.aspx.  The userid is requested from the query string.I have done some research and cannot find anything directly related, I have tried to add bits of code into what i think is the right place but I dont think what i am doing is correct. Can someone help and show me where my code is going wrong? Also is there a better/more efficient way to do what I am doing?Thanks in advance. default.aspx.csusing System;using System.Data;using System.Data.SqlClient;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        string UserID = Request.QueryString["uid"];        //string TransferPage;        if (UserID != null)                {            //initiate connection to db            SqlConnection objConnect = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);            string sql = "SELECT COUNT(*) FROM members WHERE UserID = '" + UserID + "'";            SqlCommand query = new SqlCommand(cmd, test);            int count = (int)query.ExecuteScalar();            int aantal = -1; // some default value if can't insert record            if (count == 0) // no existing record for username            {                Server.Transfer("accessdenied.aspx");            }            else            {                Session["UID"] = UserID;                Server.Transfer("welcome.aspx");                            }                    }        }} 

View 7 Replies View Related

How To Check There Is No Item In Table?

Apr 1, 2008

Hi,I want to check that Is there row exists in table or not.Please correct me.          Dim conn As SqlConnection        Dim comm As SqlCommand        Dim reader As SqlDataReader        Dim connstring As String        connstring = ConfigurationManager.ConnectionStrings("iharyana").ConnectionString        conn = New SqlConnection(connstring)        comm = New SqlCommand("select * from test where username=@username", conn)        comm.Parameters.Add("@username", Data.SqlDbType.VarChar, 20)        comm.Parameters("@username").Value = uname        conn.Open()        reader = comm.ExecuteReader        While reader.Read            If reader.Item("username").ToString = "" Then                Response.Redirect("http://www.iharyana.com")            End If                End While        reader.Close()        conn.Close()

View 1 Replies View Related

Check Previous Row In The Table

Jul 9, 2004

Hi...

Is there any way to check previous row in SQL Query?

I have a table with these column :
Name1
Name2
Audit_Time (datetime)
Changes

I want to delete record from database in which the Audit_time is <'01/05/2004'.
However before deletion, I want to check, if the Changes value is 'OLD' And the previous value is 'NEW', I will check the Audit_time of the NEW instead of OLD.


Table :
Row Name1 Name2 Audit_Time(mm/dd/yyyy) Changes
1 ABCD EFGH '01/01/2004' ADD
2 ABCD EFGHIJ '01/04/2004' NEW
3 ABCD EFGH '01/04/2004' OLD
4 Klarinda Rahmat '02/08/2004' NEW
5 Klarinda Rahmat '01/04/2004' OLD


In this case, I want to delete row 1,2,3 Where the audit_time are < '01/05/2004'.
Row 5 the audit_time also < '01/05/2004', however the changes='OLD' and the previous value changes='NEW', so I will check the Audit_Time of row 4 which is not < '01/05/2004'.
So I can't delete row5.

Is there any way to check previous row or the row before a specific row in SQL.
Any suggestion is welcomed.
Thank you in advanced.

View 2 Replies View Related

Check Table Recordcount Before Run Of DTS Pkg

Sep 12, 2006

Hi,

Could someone shed some light on the best way to check a table recordcount before run of DTS pkg.

We have a table that is populated in MS SQL from an Oracle database, and the contents of that table are the basis of a DTS package that we run.

Sometimes Oracle transfer bombs out and the table is empty but our process runs anyway. It screws everything up.

Can we check the recordcount of a table on the server, and if the recordcount > 1 then the process runs, if not, then the process aborts?

Thanks,

Dominic

View 1 Replies View Related

How To Check Seed Table?

Dec 17, 2004

Hello, everyone:

I got a new database from client. How to check which tables are seed table and truncatable? Thanks

ZYT

View 1 Replies View Related

Need To Check A Table For Errors

Feb 3, 2004

Hi - please excuse my newness to this. I have a database with several tables and one of them is causing my application to lag really bad. I figure there is either not enough space or something is just wrong in general and i don't know what. Does SQL Server have a shortcut or easy way to test a table in the database?

Thanks =)

View 6 Replies View Related

Check If The Table Exists

May 20, 2008

Hi,

This my first time using the link server to read the files directly from within SQL2005, so issues the following link:-

EXEC sp_addlinkedserver
@server = N'MYVFPSERVER', -- Your linked server name here
@srvproduct=N'Visual FoxPro 9', -- can be anything
@provider=N'VFPOLEDB',
@datasrc=N'"C:PROGRAM FILESMICROSOFT VISUAL FOXPRO 9Samplesdata estdata.dbc"'

After that i can open query and do the import issues, but how can check if the table exists before issues the query.

Best regards

View 2 Replies View Related

Check The Existency Of Table

Mar 20, 2006

Hi,

I can check the existency of the attribute in particular table. But is it possible for me to check whther my table is exist or not in that particular database?

I am using JSP

Please help!
thank you

View 2 Replies View Related

Check If A Table Is Not Empty

Nov 15, 2006

Hi,

i wanna know how can i check a table has datas inside, because i wanna use delete from table and if table is empty i dont wanna run this statement.

thanks in advance

View 5 Replies View Related

Check If A Table Is Used In Any Sp Or Function

Jul 13, 2006

Hello, there,I am trying to find out if a table is used by any of the storedprocedures or functions.I can generate all the scripts and look for it. But is there an easyway?THXJohn

View 4 Replies View Related

Check Table And STP Definition ?

Feb 7, 2008

Hi SQL Professionals ,


I have a requirement like this,

I have a Live Database as well as the Test database with the same Definition

now i need to write a SQL to check identity of these two database tables,

i mean i need to check if the Test Database has got the Same Table definition as Live Database table definition ?
In the same way how do i check for the Stored peocedures ?




how do i write a SQL for this ?


regardssuis

View 4 Replies View Related

Check Last Table Transaction

Apr 11, 2008

i have large ssis package which is scheduled daily. The package uses a table on sql server as source and because the execution time is pretty long i just want to execute the whole package only if the data in the source table has changed since the last execution. unfortunatley in the source table there is no timestamp or something like that available. so i thougt about querying some logging information. is there a system table where the time of the last table transaction is stored?

View 7 Replies View Related

Check Data Changes In Table

Oct 27, 2007

Hi all!
I need to check data changes in some tables from specified date. Can it be done without triggers for each table?
SQL Server Management Studio always says "Data was changed" if another user updates data and you try to update old version. How it checks data modification date? I found only this:


USE [ScheduleDB]

GO

SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[TTest]') AND type in ('U')

but it can only show structure modification date.

View 3 Replies View Related

How To Check If A Single Value Exists In A Table

Sep 14, 2006

What’s the easiest way to check if a single value exists in a table column?  I’m building a simple login page, and I want to get the username and check if it exists in my Users table. Here’s my SQL: SELECT UserID FROM UsersWHERE UserID = "admin" Could someone give me code to check for “admin” in my UserID column?    Here’s some code I tried, using my SqlDataSource, but it returns an error “Could not load type 'System.Data.OleDb'”     protected void Button1_Click(object sender, EventArgs e)    {        // Retreive the results from the SqlDataSource as a DataReader        OleDbDataReader reader = (OleDbDataReader)              SqlDataSource1.Select(DataSourceSelectArguments.Empty);         // Read in the value        if (reader.Read())        {             }                     // Close the reader        reader.Close();             } I don’t have to use the SqlDataSource, but originally thought it might be easier. I know how to use SqlDataSource to fill a whole GridView but this is different.  

View 2 Replies View Related

How To Check If A Value Exists In Another Table And Display The Ones That Do Not.

Jun 17, 2008

Basically, i am still relatively new to ASP.net and SQL. And i have the following query.
I have a skills table to which the user enters their skills using the following fields: Skillcatagory, SKill, Current Level, Target Level, target date and comments and the serial of the user.
I need to check via our staff table, which people have had a skill entered for them. And then produce a report on who has not had a skill entered for them.
This table has a serial of the user column aswell which is unique.
If there is more information that i can give you to assist me, please ask me.
 You help would be greatly appreciated.

View 4 Replies View Related

How To Check A Table Whether Data Is Changed Or Not..??

Jan 30, 2006

Hi..

I got 10 Tables with data in it for 100 Loans. The data can be Good and Bad .....

I had a Update Proc which Updates the 10 tables with the Good data what ever i pass...for this 100 Loans
Tha Proc will update the existing data in all tables whether it is Good or Bad Data.

when the updating is completed I want to know what are the Loans that were updated where there is a Bad Data in atleast one Field of the 10tables.

I don't want to check field by field in each table.... if there is a bad data and my proc updated with a Good Data i want to know that Loan.

Can any one has an idea on this,,,,

Thanks
Bob

View 2 Replies View Related

How To Check Existance Of Temp Table

Sep 10, 2004

Within the execution of a t-sql script how do I check for the existance of a temporary table associated with the session or a global temporary table?

My understanding is that the table name doesn't get placed in the current database sysobjects table - it goes into tempdb. But the object name is cryptic (so as to be unique) and I see no way of associating it with the current session (@@SPID).

Thanks,
Fred

View 4 Replies View Related

Table With Triggers Or Maybe A Check Constraint

May 19, 2013

I have a question about a table with triggers or maybe a check constraint.I have the following create tables:

create table bid(
seller char(10) not null,
item_nummer numeric(3) not null,
)

create table Item(
startprice char(5) not null,
description char(22) not null,
start_date char(10) not null,
end_date char(10) not null,
seller char(10) not null,
item_nummer numeric(3) not null,
)

What i'm trying to make is this trigger/constraint: colomn "seller" from table Item will get NULL as long as systemdate is > start_date and end_date, then it will get the value from seller from table bid on the same item_nummer in both table).

View 9 Replies View Related

Dynamically Check If A Table Exists

Apr 10, 2008

Hi there,
I want to create an SQL Function that checks if a table exists and returns true or false. I will pass this function a paramter (say @COMPANYID) e.g.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblmyTableName_' + @COMPANYID) and OBJECTPROPERTY(id, N'IsUserTable') = 1)

how would I write this so the query is dynamically executed and I can get a value of true or false back?

View 4 Replies View Related

Check Whether The Database Table Has Been Modified

May 9, 2008

hello everybody,


i have one problem, I want to check the database table modified or not for every five minutes , how can check? please help me


Senthil

View 2 Replies View Related

Check A Value Against Multiple Columns In Different Table

Nov 25, 2014

I have two tables table1 and table2. I want to check a value from table1 against 4 different columns in table 2. What would be the most optimized way to do this. I came up with this SQL but it runs forever.

select * from table1 a
where
(a.id in (select orig_id from table2 where exctn_dt >= '01-OCT-14')) or
(a.acct_intrl_id in (select benef_id from table2 where exctn_dt >= '01-OCT-14')) or
(a.acct_intrl_id in (select send_id from table2 where exctn_dt >= '01-OCT-14')) or
(a.acct_intrl_id in (select rcv_id from table2 where exctn_dt >= '01-OCT-14'));

View 5 Replies View Related

Check Dupplicate Entries In Table

Feb 26, 2008

Helo everybody,

How can i find a dupplicate entry in one table?

View 9 Replies View Related

Table/column Dependency Check

Dec 28, 2007

Hi All,

We have a very convoluted ETL system which is pulling unnecessary data. First thought is to restrict everything so that only the columns/tables that are necessary are brought back. We have a tons of reporting stored procedures that depend on ETL tables, is there anyway we can find out which column/tables these stored procedures are using?

Thanks!

View 3 Replies View Related

How To Check The Existence Of A Column In A Table

Jun 23, 2007

Dear All,



I wanted to know how do I know or check that whether a column exists in a table. What function or method should I use to find out that a column has already exists in a table.



When I run a T-SQL script which i have written does not work. Here is how I have written:

IF Object_ID('ColumnA') IS NOT NULL
ALTER TABLE [dbo].[Table1] DROP COLUMN [ColumnA]
GO



I badly need some help.

View 9 Replies View Related

How To Check For Table Existence Before Dropping It?

May 8, 2006

Apologies if this has been answered before, but the "Search" function doesn't seem to be working on these forums the last couple of days.

I'd just like to check if a table already exists before dropping it so that I can avoid an error if it doesn't exist. Doing a web search, I've tried along the lines of
"If (object_id(sensor_stream) is not null) drop table sensor_stream"
and
"If exists (select * from sensor_stream) drop table sensor_stream"

In both of these cases I get the error: "There was an error parsing the query. [ Token line number = 1,Token line offset = 1,Token in error = if ]"

Sooooo... what is the standard way to check for existence of a table before dropping it? Someone help? This seems like it should be simple, but I can't figure it out.

Thanks in advance!
Dana

View 7 Replies View Related

Check If Temporary Table Exists

Oct 5, 2006

Hello.



How can I check if a temporary table exists in the current context?



With normal tables I'd do a

EXISTS ( SELECT name FROM sysobjects

WHERE name='myTableName' AND type='U')

However, I can't do that with a temporary table. I'd have to go look at the sysobjects table in the tempdb database.



The problem is that for temporary tables, a suffix is added to the name to make it unique for each scope. I can't change the WHERE clause to name LIKE 'myTableName%' because this would return true if a temporary table with the same name exists in a different scope.



Any ideas?



Carlos

View 3 Replies View Related

Transact SQL :: Check Overlapping In Table

Sep 29, 2015

How can I check the overlapping in a simple table like:

Create table forum (cid int, bfrom date, tfrom date, fval int)
Insert into forum values (1, '2014-01-01', '2014-01-31',10),(2, '2014-01-01', '2014-01-31',12),(1, '2014-02-01', '2014-02-28',8),(2, '2014-02-01', '2014-02-28',6),(1, '2014-03-01', '2014-03-31',11),(2, '2014-03-01', '2014-03-31',5),(1, '2014-04-01',
'2014-04-30',14), (2, '2014-03-01', '2014-04-30',12)

In the example above there is an overlapping for the cid 2 in March. How can I check, which select should I apply?

View 5 Replies View Related

How To Check If A Temporary Table Exists?

Apr 29, 2008

I apologize if this has been asked, and answered, before. I wasn't able to find relevant posts on the forum. A Google search pointed me to a couple of pages that offered this simple recipe:

if object_id('#temp') is not null

print 'table exists';


(I have also tried 'tempdb.#temp', and 'object_id(..,'U'))

Unfortunately, this doesn't work: the condition evaluates to 'false'. #temp is alive and well: strying to 'select .. into' it raises error


> There is already an object named '#temp' in the database.

Thanks a lot!

View 6 Replies View Related

Check If A Table Exists In SQL 2005

May 9, 2007

I'm trying to check if a certain table exists in a given database on a SQL 2005 Server.

I've tried numerous times without any result.



can anyone point me in the right direction?

View 26 Replies View Related

Check Value In Table Upper Case Or Lower

Sep 20, 2006

hi i want to select * from table1 where name =petter?now if there is many type of petter in table linke  PETTER , Petter And petter which record will come in display?if i want all this three (PETTER,Petter,petter) will come in display which command is for this ??? regard

View 4 Replies View Related

Check The Field Existence Of A Database Table

Jun 5, 2007

Check the field existence of a database table, if exist get the type, size, decimal ..etc attributes
I need SP
 SP
(
@Tablename varchar(30),
@Fieldname varchar(30),
@existance char(1) OUTPUT,
@field_type varchar(30) OUTPUT,
@field_size int OUTPUT,
@field_decimal int OUTPUT
)
as
/* Below check the existance of a @Fieldname in given @Tablename */
/* And set the OUTPUT variables */
 
 
 
Thanks

View 4 Replies View Related







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