SQL Select ,Insert with multiple value

Posted on 2011-10-06
Last Modified: 2012-05-12
I have 2 table 1) Tenant ------primarykey
2) CalenderEvent-------TenantID,CalnderEvent

select t.primaryKey from tenants T,tenantRentals TR where tr.tenantID = t.primaryKey and tr.leaseEndDate > GETDATE()

from tenant table I am getting primarykey afcourse it is multiple value and  all this values

II want to insert in calender table as TenatID and also wants to insert same calender event for all TenantID.Is there any way I can do it....

Please let me know....
Question by:Itgirl16
    LVL 24

    Expert Comment


    insert into CalendarEvent (TenantID, CalnderEvent)
    select t.primaryKey, ColumnForCalendEvent
    from tenants T, tenantRentals tr
    where tr.tenantID = t.primaryKey and tr.leaseEndDate > GETDATE();

    Is that what you need?
    LVL 39

    Accepted Solution

    try like this
    Insert into CalenderEvent(TenantID,CalnderEvent)
    select t.primaryKey, 'EventValue' 
    from tenants T,tenantRentals TR where tr.tenantID = t.primaryKey and tr.leaseEndDate > GETDATE()

    Open in new window


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now