Showing posts with label names. Show all posts
Showing posts with label names. Show all posts

Friday, March 30, 2012

How to insert into Temp Table

i have temp table name "#TempResult" with column names Memberid,Month,Year. Consider this temp table alredy has some rows from previuos query. I have one more table name "Rebate" which also has columns MemberID,Month, Year and some more columns. Now i wanted to insert rows from "Rebate" Table into Temp Table where MemberID.Month and Year DOES NOT exist in Temp table.

MemberID + Month + Year should ne unique in Temp table

Maybe something like?

insert into #TempResult
select distinct
Memberid,
Month,
Year
from Rebate a
where not exists
( select 0 from #TempResult b
where a.memberid = b.memberid
and a.month = b.month
and a.year = b.year
)

Dave

|||

If you are using SQL Server 2005, you can also use the EXCEPT operator:

insert into #TempResult
select Memberid,
Month,
Year
from Rebate

except
select Memberid,
Month,
Year
from #TempResult

|||Mugambo.. thanks. but why i have to use "select 0 "instead of "select * "?|||

Lax:

You do not; I choose zero because the column selected in this case doesn't matter; what matters is whether or not the row exists. This is a semi-join? Can somebody confirm the semi-join?

Dave

|||( Maybe a left anti semi join )

Monday, March 26, 2012

How to inquire on column headings?

Hello!
I'd like to be able to find out, programmatically, what field names are there in a particular table. I use JScript and an MS Access database.
Also, if possible, if there is a particular table in the database.
And to do it so that no error message is generated.
Is there a way in SQL? I spent considerable time looking for an SQL syntax for that query, without any success.There is a MS Access forum on this site. The below should help you out:

http://www.dbforums.com/showthread.php?threadid=755288&highlight=column+names

Originally posted by masha
Hello!
I'd like to be able to find out, programmatically, what field names are there in a particular table. I use JScript and an MS Access database.
Also, if possible, if there is a particular table in the database.
And to do it so that no error message is generated.
Is there a way in SQL? I spent considerable time looking for an SQL syntax for that query, without any success.|||Originally posted by dmmac
There is a MS Access forum on this site. The below should help you out:

http://www.dbforums.com/showthread.php?threadid=755288&highlight=column+names

Thank you very much! That solves it indeed.
Sorry for posting in this forum. I did it because I hoped that it were possible using pure SQL.
Thanks again!sql

How to Index through a tables Columns

I am trying to index through the columns of MyTable so I can do the same work on all columns. I know how to get the column names from MyTable but when I use @.MyColName in the SELECT statement to get MyTable Column 0 Row values I get a table with the column name in each row cell. I can't get the syntax correct to return the value in each cell for that column.

This is a extremely simplified example !!!!!!
DECLARE @.MyColName nvarchar(30)

--Get the MyTable Column 0 Name
SELECT @.MyColName = Col_Name(Object_ID('MyTable'), 0)

--Display the MyTable Column 0 Row values
SELECT @.MyColName FROM MyTable --This is the syntax I can not get correct

Can anyone help ?

Thanks

You can't use a variable for a column name; you will have to usedynamic SQL to meet your goal. Build the SQL statement in avariable and then EXECUTE it, like this:
DECLARE @.MySQLStatement varchar(500)
SELECT @.MySQLStatement = 'SELECT ' + @.MyColName + ' FROM MyTable'
EXECUTE(@.MySQLStatement)


|||

tmorton

Thanks for your responce, I will give it a try.

Sunday, February 19, 2012

How to hide/Remove the first row of the CSV file?

I have created one report and exported in CSV file. But in CSV file, it
shows the Textbox names, table names etc in the first row. i dont want
to show the first row of the CSV result. any idea how to hide/Remove
the first row?
Regards,
VinodHmmm...tough one...
I would say you should setup a link to print another report that is the
same data but w/o the headers...There is probably a better solution but
this one would be fairly easy. If its something that you are scheduling
to be created on a share or sent out w/o headers, why include them on
the report at all?
Hope this helps!
--
Ben Sullins
http://bensullins.com