|
when my program run, i want to creat a new table, but i do not know if the name is exist.
so, i want to check that if the name can be used or no, but i don't know how to query all the table names
give me a help, please
i am just starting lerning SQL and VC++
thanks a lot
wuhuaiji
|
|
|
|
|
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name = 'table_name') CREATE TABLE table_name ( ....
"sysobjects" is the table which contains all objects created
Regards
KP
|
|
|
|
|
IF EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
AND TABLE_NAME='Student')
SELECT 'Student exists.'
ELSE
SELECT 'Student does not exist.'
-- or
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME='Student'
-- or
SELECT * FROM sysobjects WHERE name='Student'
--OR
IF OBJECT_ID('Student') IS NOT NULL
PRINT 'Student exists.'
ELSE
PRINT 'Student does not exist.'
Never Think That You Have Failed Instead Always Think That u hav Better Chance Next Time...
|
|
|
|
|
Hi,
I created a function to check if a table exists, as I need to check for this sort of thing frequently.
Here is the function code:
<code>
CREATE function dbo.DoesObjectExist(@Name varchar(200), @Type char(1))
returns varchar(7)
begin
declare @Result varchar(7)
if exists (select * from sysobjects
where name = @Name
and xtype = @Type)
select @Result = 'present'
else
select @Result = ''
return @Result
end
This is how you check if the OffVansQtyOrdered table exists using this function:
<code>
if dbo.DoesObjectExist('OffVansQtyOrdered','u') = 'present'
I hope this is of help...
You always pass failure on the way to success.
|
|
|
|
|
firstly thanks again,
by the way,i am so sorry, that i do not really understand what you write above, and i do not know in VC++ , how to create a table, just like the question i write "a problem about m_pConnection->Execute", have you a good way to resolve it, or can can you tell me which problem exist in my program
wuhuaiji
|
|
|
|
|
Hi,
The first example is what is called a "user defined function".
This is a means for SQL to process data based on parameters passed to the function and then return a value(or a table).
In this case the function takes an object and object type as input.
The object type, in the bottom piece of code, is "u" which means that the function only looks for tables.
The advantage of a function is that you can create this code once and reuse it many times by just calling it with dbo.DoesObjectExist('tablename','u').
In terms of creating a SQL table in C++ I'm sorry to say that I cannot help you with that yet as I am learning C# at the moment.
What I can recommend is google and searches with strings such as "create SQL table with C++" and "SQL create table".
As a tool google is invaluable and has proved to be just this in my work - as there is always going to be an example somewhere out there of what you are trying to do.
Good luck.
You always pass failure on the way to success.
|
|
|
|
|
hi every body
i have my project that i have pages that contains grid views then with updating sume page the underlining under page number became hidden and some pages still underline under page number visible what happend and how i can make the pages page underlines visible thx in advance.
let's work together
|
|
|
|
|
how to find the last value in a Table .
My table was designed by another person ..it doesnt have any Identity column ..
It has only EMPname,Empaddress,EmpContactno.
can any one pls tell me how to find the last value in the table
Thanks in advance
Regards
Bino varghese
|
|
|
|
|
you mean to say u want a last record of the Table...is that so...
|
|
|
|
|
if i m getting you correct so let me tell you there is no such way by which u can get the last row of the tabe u shuld be more specific abut ur query..but there is a way by which u can achieve ur task.
select top 1 * from table
order by somefield
Hope it will work for you.
Thanks and regards
Aavesh Agaerwal
|
|
|
|
|
Last value by what criteria?
|
|
|
|
|
Not sure why you need this bug:
SELECT TOP 1 X
FROM TABLE
ORDER BY X DESC
|
|
|
|
|
hi all
Thanks for ur reply..
If I order by I vl not get the last value in the table..
I want the last record in the table .
|
|
|
|
|
One of the fundamental principles of a relational database is that the physical order of rows and columns in the tuples (tables) is not important.
http://en.wikipedia.org/wiki/Relational_database[^]
If you need to extract data in a particular order, the data itself should provide the means of doing this. For instance, if you had an numeric EmployeeID field which was incremented every time a new employee joined the company then you could find the last value in your table by selecting the row of data with the highest EmployeeID value. You don't have any data items that you can use for this purpose in your table so you can't achieve this.
Paul Marfleet
|
|
|
|
|
Suppose if i have 4 After triggers and i want to give the order for them in which they fired i can do that with the help of sp_setordertrigger but with this i can only specify which one can be fired first and last one but what abut the rest of triggers how can i order them..please help me..in this i m new for trigger...
Sucess need one master Stroke
Thanks and Regards
Aavesh Agarwal
|
|
|
|
|
How can we swap the values of the Two columns..using query
is it possible or not if it is then how?
Please let me know the query.......
-- modified at 5:26 Wednesday 10th October, 2007
|
|
|
|
|
Aavesh Agarwal wrote: swap the values of the Two columns
Assuming that both the columns are of the same data type
update yourtable set columnA = columnB, columnB = columnA
|
|
|
|
|
thanks for ur reply..its working but logically how it happens in sqlserver..by using a=b or b=a ..it will not give the same values in the both the columns...
|
|
|
|
|
hi this is ajay rathi,
i am facing a very big problem,
select month(Start_date) as start_Month, year(Start_date) as start_Year,
sum(case when Status = 'Active' then 1
else 0 end) as Active,
sum(case when Status = 'Inactive' then 1
else 0 end) as Billed
from tbl_Post_Job where Company_Id_Fk = 60 and Start_date between Start_date and Exp_date group by year(Start_date), month(Start_date)order by year(Start_date), month(Start_date)
in this query i want many things,first of all i want to say this is not right query i want query from you..
(1)month(Start_date) as start_Month, year(Start_date) as start_Year
from this line i want month and year from Start_date to Exp_date
(2)in active condition,if any company's status is active from january to april so in this condition the entry of active should be come in january to april in every month
(3)group by year(Start_date), month(Start_date)
in group by section same problem,i want data from Start_date to exp_date
actually the main problem i m facing is this that when i need month and year together and active postion and billed position saperatlly..
actually i need this data in following form...
Date | Active | Billed
------------------------------------
january,2007 | 4 | 2
feburary,2007 | 7 | 5
march,2007 | 4 | 2
april,2007 | 6 | 4
------------------------------------
january,2007 is the start_date and april,2007 is the exp_date
actualy above data january,2007 is coming in form of 1,2007 but i need this data in form of january,2007 so plz tell me how can i convert this data...
plz if any one needs any clarification then plz ask me about this because i need this query immediatly..
plz try to help me as soon as posible
Ajay Rathi
software engineer
NOIDA(UP),INDIA
|
|
|
|
|
hi Ajay
Actually i didn't undestand your Qn...
but using the below qry u will get the name of the month..
select datename(month,month(start_date)) from <tablename>
Regards
Joe
|
|
|
|
|
you gave me solution of one problem "datename(month,month(start_date))"
but this is giving me again and again only "january" nothing else..
so plz give me the other solution..
and wht you could not under stand in my first problem plz tell me....
i need the solution...
plzzzzzzzz
Ajay Rathi
software engineer
NOIDA(UP),INDIA
|
|
|
|
|
Arihant rathi wrote: plzzzzzzzz
Enough with the textspeak please. It's really annoying.
If you want to get the year/month description, concatenate the result of datename(month,month(start_date)) and year(start_date) .
Paul Marfleet
|
|
|
|
|
sorry for the wrong Qry
correct one is
select DATENAME(month, start_date) from <tablename>
|
|
|
|
|
hi,
I am using MySql .NET Connector 5.1.2.
Following is the code I am using to read a longblob field from a table..
string selCmd = "SELECT * FROM document";<br />
MySqlCommand allDocsCmd = new MySqlCommand(selCmd, con);<br />
MySqlDataReader reader = allDocsCmd.ExecuteReader();<br />
reader.Close();
The execution hangs at reader.Close();
When I selected everything else but the blob field from the table and it worked fine i.e.
"select id,data from document" hangs but
"select id from document" works ok.
('data' is a LONGBLOB field in document table)
I am searching a cause and fix but lemme know if anyone has ne idea why this is happening..
Thanx.
-- modified at 9:56 Wednesday 10th October, 2007
|
|
|
|
|
hi!1
Actually i am a beginner with asp.net and databases .
i want to know that how can i access values from a table where some column name has null value say parentId ..
Mrinal
|
|
|
|